Class: Natives::Catalog::Merger

Inherits:
Object
  • Object
show all
Defined in:
lib/natives/catalog/merger.rb

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}) ⇒ Merger

Returns a new instance of Merger.



6
7
8
# File 'lib/natives/catalog/merger.rb', line 6

def initialize(opts={})
  @validator = opts.fetch(:validator, Validator.new)
end

Instance Method Details

#merge_catalog!(master_hash, hash_to_merge) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/natives/catalog/merger.rb', line 10

def merge_catalog!(master_hash, hash_to_merge)
  @validator.ensure_valid_catalog_groups(master_hash)
  @validator.ensure_valid_catalog_groups(hash_to_merge)

  hash_to_merge.each do |group_name, entries|
    if master_hash.key? group_name
      master_hash[group_name].merge! entries
    else
      master_hash[group_name] = entries
    end
  end

  master_hash
end