Class: Mantra::Commands::Merge

Inherits:
Mantra::Command show all
Defined in:
lib/mantra/commands/merge.rb

Instance Attribute Summary collapse

Attributes inherited from Mantra::Command

#options

Instance Method Summary collapse

Methods inherited from Mantra::Command

description, full_description, #initialize, option, option_descriptors, #parse_options, #run, usage

Methods included from Helpers::ObjectWithType

included

Constructor Details

This class inherits a constructor from Mantra::Command

Instance Attribute Details

#manifestObject

Returns the value of attribute manifest.



17
18
19
# File 'lib/mantra/commands/merge.rb', line 17

def manifest
  @manifest
end

Instance Method Details

#performObject



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/mantra/commands/merge.rb', line 19

def perform
  if json.nil? && file.nil?
    raise "json of file should be specified"
  end

  json_string = json.nil? ? File.read(file) : json
  object_to_merge = JSON.parse(json_string)
  element_to_merge = Mantra::Manifest::Element.create(object_to_merge)
  manifest = Mantra::Manifest.new(manifest_path)
  manifst_elements  = manifest.select(path || "")
  manifst_elements.each do |e|
    e.merge(element_to_merge, force: true)
  end
  puts manifest.to_ruby_object.to_yaml
end