Class: Etna::Clients::Magma::FileAttributesBlankWorkflow
- Inherits:
-
Struct
- Object
- Struct
- Etna::Clients::Magma::FileAttributesBlankWorkflow
- Defined in:
- lib/etna/clients/magma/workflows/file_attributes_blank_workflow.rb
Instance Attribute Summary collapse
-
#magma_crud ⇒ Object
Returns the value of attribute magma_crud.
-
#model_names ⇒ Object
Returns the value of attribute model_names.
-
#project_name ⇒ Object
Returns the value of attribute project_name.
Instance Method Summary collapse
- #each_revision ⇒ Object
- #find_file_and_image_attributes ⇒ Object
-
#initialize(opts) ⇒ FileAttributesBlankWorkflow
constructor
A new instance of FileAttributesBlankWorkflow.
- #magma_client ⇒ Object
- #models ⇒ Object
- #revision_for(attribute_name) ⇒ Object
- #set_file_attrs_blank ⇒ Object
Constructor Details
#initialize(opts) ⇒ FileAttributesBlankWorkflow
Returns a new instance of FileAttributesBlankWorkflow.
9 10 11 |
# File 'lib/etna/clients/magma/workflows/file_attributes_blank_workflow.rb', line 9 def initialize(opts) super(**{}.update(opts)) end |
Instance Attribute Details
#magma_crud ⇒ Object
Returns the value of attribute magma_crud
7 8 9 |
# File 'lib/etna/clients/magma/workflows/file_attributes_blank_workflow.rb', line 7 def magma_crud @magma_crud end |
#model_names ⇒ Object
Returns the value of attribute model_names
7 8 9 |
# File 'lib/etna/clients/magma/workflows/file_attributes_blank_workflow.rb', line 7 def model_names @model_names end |
#project_name ⇒ Object
Returns the value of attribute project_name
7 8 9 |
# File 'lib/etna/clients/magma/workflows/file_attributes_blank_workflow.rb', line 7 def project_name @project_name end |
Instance Method Details
#each_revision ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/etna/clients/magma/workflows/file_attributes_blank_workflow.rb', line 29 def each_revision find_file_and_image_attributes.each do |model_name, attribute_names| # Query all records in this model request = Etna::Clients::Magma::RetrievalRequest.new(project_name: project_name) request.model_name = model_name request.attribute_names = attribute_names request.record_names = 'all' documents = magma_client.retrieve(request).models.model(model_name).documents documents.document_keys.each do |record_name| document = documents.document(record_name) attribute_names.each do |attribute_name| yield [model_name, record_name, attribute_name] if !document[attribute_name] end end end end |
#find_file_and_image_attributes ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/etna/clients/magma/workflows/file_attributes_blank_workflow.rb', line 17 def find_file_and_image_attributes {}.tap do |all_matches| model_names.each do |model_name| attribute_names = models.model(model_name).template.attributes.all.select {|a| a.attribute_type == Etna::Clients::Magma::AttributeType::FILE || a.attribute_type == Etna::Clients::Magma::AttributeType::IMAGE}.map { |a| a.attribute_name} all_matches[model_name] = attribute_names end end end |
#magma_client ⇒ Object
13 14 15 |
# File 'lib/etna/clients/magma/workflows/file_attributes_blank_workflow.rb', line 13 def magma_client magma_crud.magma_client end |
#models ⇒ Object
59 60 61 62 63 |
# File 'lib/etna/clients/magma/workflows/file_attributes_blank_workflow.rb', line 59 def models @models ||= begin magma_client.retrieve(RetrievalRequest.new(project_name: self.project_name, model_name: 'all')).models end end |
#revision_for(attribute_name) ⇒ Object
55 56 57 |
# File 'lib/etna/clients/magma/workflows/file_attributes_blank_workflow.rb', line 55 def revision_for(attribute_name) {attribute_name => {path: "::blank"}} end |
#set_file_attrs_blank ⇒ Object
47 48 49 50 51 52 53 |
# File 'lib/etna/clients/magma/workflows/file_attributes_blank_workflow.rb', line 47 def set_file_attrs_blank magma_crud.update_records do |update_request| each_revision do |model_name, record_name, attribute_name| update_request.update_revision(model_name, record_name, revision_for(attribute_name)) end end end |