Class: Etna::Clients::Magma::AddProjectModelsWorkflow
- Inherits:
-
Struct
- Object
- Struct
- Etna::Clients::Magma::AddProjectModelsWorkflow
- Defined in:
- lib/etna/clients/magma/workflows/add_project_models_workflow.rb
Instance Attribute Summary collapse
-
#magma_client ⇒ Object
Returns the value of attribute magma_client.
Class Method Summary collapse
Instance Method Summary collapse
- #apply_matrix_constants(changeset) ⇒ Object
- #plan_synchronization(changeset, project, target_model = 'project') ⇒ Object
- #prepare_changeset_from_csv(filename: nil, io: nil, &err_block) ⇒ Object
- #write_models_template_csv(project_name, target_model = 'project', filename: nil, io: nil) ⇒ Object
Instance Attribute Details
#magma_client ⇒ Object
Returns the value of attribute magma_client
12 13 14 |
# File 'lib/etna/clients/magma/workflows/add_project_models_workflow.rb', line 12 def magma_client @magma_client end |
Class Method Details
.validate_changeset(changeset, &err_block) ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/etna/clients/magma/workflows/add_project_models_workflow.rb', line 46 def self.validate_changeset(changeset, &err_block) changeset.models.model_keys.each do |model_name| validator = AddModelValidator.new(changeset.models, model_name) validator.validate validator.errors.each(&err_block) end validator = RenamesValidator.new(changeset.models, changeset.renames) validator.validate validator.errors.each(&err_block) end |
Instance Method Details
#apply_matrix_constants(changeset) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/etna/clients/magma/workflows/add_project_models_workflow.rb', line 22 def apply_matrix_constants(changeset) changeset.models.model_keys.each do |model_name| model = changeset.models.model(model_name) attributes = model.template.attributes attributes.attribute_keys.each do |attribute_name| attribute = attributes.attribute(attribute_name) next unless (validation = attribute&.validation) next unless (value = validation['value']) if validation['type'] == 'Array' && value&.first.start_with?(Etna::Clients::Magma::ModelsCsv::COPY_OPTIONS_SENTINEL) digest = value&.first.slice((Etna::Clients::Magma::ModelsCsv::COPY_OPTIONS_SENTINEL.length)..-1) attribute.validation = { 'type' => 'Array', 'value' => changeset.matrix_constants[digest] } end end end end |
#plan_synchronization(changeset, project, target_model = 'project') ⇒ Object
13 14 15 16 17 18 19 20 |
# File 'lib/etna/clients/magma/workflows/add_project_models_workflow.rb', line 13 def plan_synchronization(changeset, project, target_model = 'project') apply_matrix_constants(changeset) workflow = ModelSynchronizationWorkflow.new(target_client: magma_client, source_models: changeset.models, renames: changeset.renames, target_project: project, plan_only: true) workflow.ensure_model_tree(target_model) workflow end |
#prepare_changeset_from_csv(filename: nil, io: nil, &err_block) ⇒ Object
39 40 41 42 43 44 |
# File 'lib/etna/clients/magma/workflows/add_project_models_workflow.rb', line 39 def prepare_changeset_from_csv(filename: nil, io: nil, &err_block) importer = ModelsCsv::Importer.new changeset = importer.prepare_changeset(filename: filename, input_io: io, &err_block) self.class.validate_changeset(changeset, &err_block) changeset end |
#write_models_template_csv(project_name, target_model = 'project', filename: nil, io: nil) ⇒ Object
58 59 60 61 62 63 |
# File 'lib/etna/clients/magma/workflows/add_project_models_workflow.rb', line 58 def write_models_template_csv(project_name, target_model = 'project', filename: nil, io: nil) models = magma_client.retrieve(RetrievalRequest.new(project_name: project_name, model_name: 'all')).models descendants = models.to_directed_graph.descendants(target_model) exporter = ModelsCsv::Exporter.new exporter.write_models(models, [target_model] + descendants.keys, filename: filename, output_io: io) end |