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



40
41
42
43
44
# File 'lib/labimotion/models/concerns/datasetable.rb', line 40

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



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

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