Module: Labimotion::Datasetable

Extended by:
ActiveSupport::Concern
Defined in:
lib/labimotion/models/concerns/datasetable.rb

Overview

Datasetable concern

Instance Method Summary collapse

Instance Method Details

#destroy_datasetableObject



44
45
46
47
48
# File 'lib/labimotion/models/concerns/datasetable.rb', line 44

def destroy_datasetable
  return if not_dataset?

  Labimotion::Dataset.where(element_type: self.class.name, element_id: id).destroy_all
end

#not_dataset?Boolean

Returns:

  • (Boolean)


14
15
16
# File 'lib/labimotion/models/concerns/datasetable.rb', line 14

def not_dataset?
  self.class.name == 'Container' && container_type != 'dataset'
end

#save_dataset(**args) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/labimotion/models/concerns/datasetable.rb', line 18

def save_dataset(**args)
  return if not_dataset?

  klass = Labimotion::DatasetKlass.find_by(id: args[:dataset_klass_id])
  uuid = SecureRandom.uuid
  props = args[:properties]
  props['eln'] = Chemotion::Application.config.version
  props['labimotion'] = Labimotion::VERSION
  ds = Labimotion::Dataset.find_by(element_type: self.class.name, element_id: id)
  if ds.present? && (ds.klass_uuid != props['klass_uuid'] || ds.properties != props)
    props['uuid'] = uuid
    props['eln'] = Chemotion::Application.config.version
    props['labimotion'] = Labimotion::VERSION
    props['klass'] = 'Dataset'
    ds.update!(properties_release: klass.properties_release, uuid: uuid, dataset_klass_id: args[:dataset_klass_id], properties: props, klass_uuid: props['klass_uuid'])
  end
  return if ds.present?

  props['uuid'] = uuid
  props['klass_uuid'] = klass.uuid
  props['eln'] = Chemotion::Application.config.version
  props['labimotion'] = Labimotion::VERSION
  props['klass'] = 'Dataset'
  Labimotion::Dataset.create!(properties_release: klass.properties_release, uuid: uuid, dataset_klass_id: args[:dataset_klass_id], element_type: self.class.name, element_id: id, properties: props, klass_uuid: klass.uuid)
end