Module: ForemanMaintain::Utils::HashTools

Defined in:
lib/foreman_maintain/utils/hash_tools.rb

Class Method Summary collapse

Class Method Details

.deep_merge!(hash, other_hash) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
# File 'lib/foreman_maintain/utils/hash_tools.rb', line 3

def self.deep_merge!(hash, other_hash)
  other_hash = symbolize_hash(other_hash)

  hash.merge!(other_hash) do |_key, old_val, new_val|
    if old_val.is_a?(Hash) && new_val.is_a?(Hash)
      deep_merge!(old_val, new_val)
    elsif old_val.is_a?(Array) && new_val.is_a?(Array)
      old_val + new_val
    else
      new_val
    end
  end
end

.symbolize_hash(hash) ⇒ Object



17
18
19
# File 'lib/foreman_maintain/utils/hash_tools.rb', line 17

def self.symbolize_hash(hash)
  hash.inject({}) { |sym_hash, (key, value)| sym_hash.update(key.to_sym => value) }
end