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(csv_io, &err_block) ⇒ Object
- #write_models_template_csv(io, project_name, target_model = 'project') ⇒ 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
55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/etna/clients/magma/workflows/add_project_models_workflow.rb', line 55 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?(ModelsCsv::COPY_OPTIONS_SENTINEL) digest = value&.first.slice((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(csv_io, &err_block) ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/etna/clients/magma/workflows/add_project_models_workflow.rb', line 39 def prepare_changeset_from_csv(csv_io, &err_block) line_no = 0 csv_lines = CSV.parse(csv_io, headers: true, header_converters: :symbol) changeset = csv_lines.inject(ModelsCsv::ModelsChangeset.new) do |acc, n| line_no += 1 ModelsCsv.apply_csv_row(acc, n) do |err| err_block.call("Error detected on line #{line_no + 1}: #{err}") return end end self.class.validate_changeset(changeset, &err_block) changeset end |
#write_models_template_csv(io, project_name, target_model = 'project') ⇒ Object
67 68 69 70 71 72 73 74 |
# File 'lib/etna/clients/magma/workflows/add_project_models_workflow.rb', line 67 def write_models_template_csv(io, project_name, target_model = 'project') models = magma_client.retrieve(RetrievalRequest.new(project_name: project_name, model_name: 'all')).models descendants = models.to_directed_graph.descendants(target_model) csv = CSV.new(io) ModelsCsv.each_csv_row(models, [target_model] + descendants.keys) do |row| csv << row end end |