Module: ForemanMaintain::Utils::HashTools

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

Class Method Summary collapse

Class Method Details

.deep_merge!(h, other_h) ⇒ 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!(h, other_h)
  other_h = symbolize_hash(other_h)

  h.merge!(other_h) 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(h) ⇒ Object



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

def self.symbolize_hash(h)
  h.inject({}) { |sym_hash, (k, v)| sym_hash.update(k.to_sym => v) }
end