Module: Raven::Utils::DeepMergeHash

Defined in:
lib/raven/utils/deep_merge.rb

Overview

ported from ActiveSupport

Class Method Summary collapse

Class Method Details

.deep_merge(hash, other_hash, &block) ⇒ Object



6
7
8
# File 'lib/raven/utils/deep_merge.rb', line 6

def self.deep_merge(hash, other_hash, &block)
  deep_merge!(hash, other_hash, &block)
end

.deep_merge!(hash, other_hash, &block) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/raven/utils/deep_merge.rb', line 10

def self.deep_merge!(hash, other_hash, &block)
  other_hash.each_pair do |current_key, other_value|
    this_value = hash[current_key]

    hash[current_key] = if this_value.is_a?(Hash) && other_value.is_a?(Hash)
      this_value.deep_merge(other_value, &block)
    else
      if block_given? && key?(current_key)
        block.call(current_key, this_value, other_value)
      else
        other_value
      end
    end
  end

  hash
end