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

#copy_dataset(orig_ds) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/labimotion/models/concerns/datasetable.rb', line 19

def copy_dataset(orig_ds)
  return if orig_ds.dataset.nil?

  ods = orig_ds.dataset
  uuid = SecureRandom.uuid
  dataset = Labimotion::Dataset.create!(
    uuid: uuid,
    dataset_klass_id: ods.dataset_klass_id,
    element_type: 'Container',
    element_id: self.id,
    properties: ods.properties,
    properties_release: ods.properties_release,
    klass_uuid: ods.klass_uuid,
  )
end

#destroy_datasetableObject



56
57
58
59
60
# File 'lib/labimotion/models/concerns/datasetable.rb', line 56

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)


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

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

#save_dataset(**args) ⇒ Object



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/labimotion/models/concerns/datasetable.rb', line 35

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['pkg'] = Labimotion::Utils.pkg(props['pkg'])
  props['identifier'] = klass.identifier if klass.identifier.present?
  props['uuid'] = uuid
  props['klass'] = 'Dataset'

  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)
    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['klass_uuid'] = klass.uuid
  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