Class: Etna::Clients::Magma::UpdateRequest

Inherits:
Struct
  • Object
show all
Includes:
JsonSerializableStruct, MultipartSerializableNestedHash
Defined in:
lib/etna/clients/magma/models.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from MultipartSerializableNestedHash

#encode_multipart_content, included

Methods included from JsonSerializableStruct

#as_json, included, #to_json

Constructor Details

#initialize(**params) ⇒ UpdateRequest

Returns a new instance of UpdateRequest.



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

def initialize(**params)
  super({revisions: {}, dry_run: false}.update(params))
end

Instance Attribute Details

#dry_runObject

Returns the value of attribute dry_run

Returns:

  • (Object)

    the current value of dry_run



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

def dry_run
  @dry_run
end

#project_nameObject

Returns the value of attribute project_name

Returns:

  • (Object)

    the current value of project_name



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

def project_name
  @project_name
end

#revisionsObject

Returns the value of attribute revisions

Returns:

  • (Object)

    the current value of revisions



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

def revisions
  @revisions
end

Instance Method Details

#append_table(parent_model_name, parent_record_name, model_name, attrs, attribute_name = model_name) ⇒ Object



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

def append_table(parent_model_name, parent_record_name, model_name, attrs, attribute_name = model_name)
  parent_revision = update_revision(parent_model_name, parent_record_name, {})
  table = parent_revision[attribute_name] ||= []
  id = "::#{model_name}#{(revisions[model_name] || {}).length + 1}"
  table << id
  update_revision(model_name, id, attrs)
  id
end

#update_revision(model_name, record_name, attrs) ⇒ Object



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

def update_revision(model_name, record_name, attrs)
  revision = revisions[model_name] ||= {}
  record = revision[record_name] ||= {}
  record.update(attrs)
end