Class: Etna::Clients::Magma::EnsureContainingRecordWorkflow
- Inherits:
-
Struct
- Object
- Struct
- Etna::Clients::Magma::EnsureContainingRecordWorkflow
- Defined in:
- lib/etna/clients/magma/workflows/ensure_containing_record_workflow.rb
Instance Attribute Summary collapse
-
#magma_crud ⇒ Object
Returns the value of attribute magma_crud.
-
#models ⇒ Object
Returns the value of attribute models.
Class Method Summary collapse
Instance Method Summary collapse
Instance Attribute Details
#magma_crud ⇒ Object
Returns the value of attribute magma_crud
7 8 9 |
# File 'lib/etna/clients/magma/workflows/ensure_containing_record_workflow.rb', line 7 def magma_crud @magma_crud end |
#models ⇒ Object
Returns the value of attribute models
7 8 9 |
# File 'lib/etna/clients/magma/workflows/ensure_containing_record_workflow.rb', line 7 def models @models end |
Class Method Details
.from_remote_models(magma_crud:, **opts) ⇒ Object
8 9 10 11 12 |
# File 'lib/etna/clients/magma/workflows/ensure_containing_record_workflow.rb', line 8 def self.from_remote_models(magma_crud:, **opts) opts[:models] = magma_crud.magma_client.retrieve(RetrievalRequest.new(project_name: magma_crud.project_name, model_name: 'all')).models opts[:magma_crud] = magma_crud self.class.new(**opts) end |
Instance Method Details
#ensure_record(model_name, record_identifiers) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/etna/clients/magma/workflows/ensure_containing_record_workflow.rb', line 18 def ensure_record(model_name, record_identifiers) raise "Could not find containing model #{model_name} defined." unless (model = models.model(model_name)) raise "Identifiers #{record_identifiers} do not contain #{model_name}" unless (id = record_identifiers[model_name]) record = magma_crud.lookup_record(model_name, id) if record.nil? attrs = { model.template.identifier => id } parent_attr = model.template.attributes.all.select { |a| a.attribute_type == AttributeType::PARENT }.first unless parent_attr.nil? parent_attribute_name = parent_attr.attribute_name parent_identifier = ensure_record(model.template.parent, record_identifiers) attrs.update({parent_attribute_name => parent_identifier}) end magma_crud.update_records do |update_request| update_request.update_revision(model_name, id, attrs) end end id end |
#magma_client ⇒ Object
14 15 16 |
# File 'lib/etna/clients/magma/workflows/ensure_containing_record_workflow.rb', line 14 def magma_client magma_crud.magma_client end |