Class: Etna::Clients::Magma::UpdateAttributesFromCsvWorkflowBase

Inherits:
Struct
  • Object
show all
Defined in:
lib/etna/clients/magma/workflows/update_attributes_from_csv_workflow.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opts) ⇒ UpdateAttributesFromCsvWorkflowBase

Returns a new instance of UpdateAttributesFromCsvWorkflowBase.



9
10
11
# File 'lib/etna/clients/magma/workflows/update_attributes_from_csv_workflow.rb', line 9

def initialize(opts)
  super(**{}.update(opts))
end

Instance Attribute Details

#filepathObject

Returns the value of attribute filepath

Returns:

  • (Object)

    the current value of filepath



8
9
10
# File 'lib/etna/clients/magma/workflows/update_attributes_from_csv_workflow.rb', line 8

def filepath
  @filepath
end

#hole_valueObject

Returns the value of attribute hole_value

Returns:

  • (Object)

    the current value of hole_value



8
9
10
# File 'lib/etna/clients/magma/workflows/update_attributes_from_csv_workflow.rb', line 8

def hole_value
  @hole_value
end

#json_valuesObject

Returns the value of attribute json_values

Returns:

  • (Object)

    the current value of json_values



8
9
10
# File 'lib/etna/clients/magma/workflows/update_attributes_from_csv_workflow.rb', line 8

def json_values
  @json_values
end

#magma_crudObject

Returns the value of attribute magma_crud

Returns:

  • (Object)

    the current value of magma_crud



8
9
10
# File 'lib/etna/clients/magma/workflows/update_attributes_from_csv_workflow.rb', line 8

def magma_crud
  @magma_crud
end

#model_nameObject

Returns the value of attribute model_name

Returns:

  • (Object)

    the current value of model_name



8
9
10
# File 'lib/etna/clients/magma/workflows/update_attributes_from_csv_workflow.rb', line 8

def model_name
  @model_name
end

#project_nameObject

Returns the value of attribute project_name

Returns:

  • (Object)

    the current value of project_name



8
9
10
# File 'lib/etna/clients/magma/workflows/update_attributes_from_csv_workflow.rb', line 8

def project_name
  @project_name
end

Instance Method Details

#consolidate_attributes_to_hash(row) ⇒ Object



25
26
27
# File 'lib/etna/clients/magma/workflows/update_attributes_from_csv_workflow.rb', line 25

def consolidate_attributes_to_hash(row)
  raise "Must be implemented in a subclass"
end

#each_revisionObject



33
34
35
36
37
# File 'lib/etna/clients/magma/workflows/update_attributes_from_csv_workflow.rb', line 33

def each_revision
  parse_input_file do |model_name, record_name, revision|
    yield [model_name, record_name, revision]
  end
end

#find_attribute(model_name, attribute_name) ⇒ Object



29
30
31
# File 'lib/etna/clients/magma/workflows/update_attributes_from_csv_workflow.rb', line 29

def find_attribute(model_name, attribute_name)
  models.model(model_name).template.attributes.attribute(attribute_name)
end

#magma_clientObject



13
14
15
# File 'lib/etna/clients/magma/workflows/update_attributes_from_csv_workflow.rb', line 13

def magma_client
  magma_crud.magma_client
end

#model_exists?(model_name) ⇒ Boolean

Returns:

  • (Boolean)


21
22
23
# File 'lib/etna/clients/magma/workflows/update_attributes_from_csv_workflow.rb', line 21

def model_exists?(model_name)
  models.model(model_name)
end

#modelsObject



47
48
49
50
51
# File 'lib/etna/clients/magma/workflows/update_attributes_from_csv_workflow.rb', line 47

def models
  @models ||= begin
    magma_client.retrieve(RetrievalRequest.new(project_name: self.project_name, model_name: 'all')).models
  end
end

#parse_input_fileObject



17
18
19
# File 'lib/etna/clients/magma/workflows/update_attributes_from_csv_workflow.rb', line 17

def parse_input_file
  raise "Must be implemented in a subclass"
end

#update_attributesObject



39
40
41
42
43
44
45
# File 'lib/etna/clients/magma/workflows/update_attributes_from_csv_workflow.rb', line 39

def update_attributes
  magma_crud.update_records(method: :update_json) do |update_request|
    each_revision do |model_name, record_name, revision|
      update_request.update_revision(model_name, record_name, revision)
    end
  end
end