Class: Etna::Clients::Magma::AttributeActionsFromJsonWorkflow
- Inherits:
-
Struct
- Object
- Struct
- Etna::Clients::Magma::AttributeActionsFromJsonWorkflow
- Defined in:
- lib/etna/clients/magma/workflows/attribute_actions_from_json_workflow.rb
Overview
Note! These workflows are not perfectly atomic, nor perfectly synchronized due to nature of the backend. These primitives are best effort locally synchronized, but cannot defend the backend or simultaneous system updates.
Instance Attribute Summary collapse
-
#actions ⇒ Object
readonly
Returns the value of attribute actions.
-
#filepath ⇒ Object
Returns the value of attribute filepath.
-
#magma_client ⇒ Object
Returns the value of attribute magma_client.
-
#project_name ⇒ Object
Returns the value of attribute project_name.
Instance Method Summary collapse
- #execute_actions ⇒ Object
- #format_errors(errors) ⇒ Object
-
#initialize(**params) ⇒ AttributeActionsFromJsonWorkflow
constructor
A new instance of AttributeActionsFromJsonWorkflow.
- #project_models ⇒ Object
- #run! ⇒ Object
Constructor Details
#initialize(**params) ⇒ AttributeActionsFromJsonWorkflow
Returns a new instance of AttributeActionsFromJsonWorkflow.
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/etna/clients/magma/workflows/attribute_actions_from_json_workflow.rb', line 22 def initialize(**params) super({}.update(params)) actions_json = JSON.parse(File.read(filepath)) converter = Etna::Clients::Magma::AttributeActionsConverter.new(actions_json) @actions = converter.convert validator = Etna::Clients::Magma::AttributeActionsValidator.new( actions, project_models) validator.validate raise "Attributes JSON has errors:\n * #{format_errors(validator.errors)}" unless validator.valid? end |
Instance Attribute Details
#actions ⇒ Object (readonly)
Returns the value of attribute actions.
21 22 23 |
# File 'lib/etna/clients/magma/workflows/attribute_actions_from_json_workflow.rb', line 21 def actions @actions end |
#filepath ⇒ Object
Returns the value of attribute filepath
20 21 22 |
# File 'lib/etna/clients/magma/workflows/attribute_actions_from_json_workflow.rb', line 20 def filepath @filepath end |
#magma_client ⇒ Object
Returns the value of attribute magma_client
20 21 22 |
# File 'lib/etna/clients/magma/workflows/attribute_actions_from_json_workflow.rb', line 20 def magma_client @magma_client end |
#project_name ⇒ Object
Returns the value of attribute project_name
20 21 22 |
# File 'lib/etna/clients/magma/workflows/attribute_actions_from_json_workflow.rb', line 20 def project_name @project_name end |
Instance Method Details
#execute_actions ⇒ Object
48 49 50 51 52 |
# File 'lib/etna/clients/magma/workflows/attribute_actions_from_json_workflow.rb', line 48 def execute_actions magma_client.update_model(Etna::Clients::Magma::UpdateModelRequest.new( project_name: project_name, actions: actions)) end |
#format_errors(errors) ⇒ Object
38 39 40 |
# File 'lib/etna/clients/magma/workflows/attribute_actions_from_json_workflow.rb', line 38 def format_errors(errors) errors.map { |e| e.gsub("\n", "\n\t") }.join("\n * ") end |
#project_models ⇒ Object
42 43 44 45 46 |
# File 'lib/etna/clients/magma/workflows/attribute_actions_from_json_workflow.rb', line 42 def project_models @project_models ||= magma_client.retrieve(Etna::Clients::Magma::RetrievalRequest.new( project_name: project_name, model_name: 'all')).models end |
#run! ⇒ Object
54 55 56 57 58 |
# File 'lib/etna/clients/magma/workflows/attribute_actions_from_json_workflow.rb', line 54 def run! puts "Executing the attribute actions against Magma." execute_actions puts "All complete!" end |