Module: Caoutsearch::Search::Query::Merge

Included in:
Base
Defined in:
lib/caoutsearch/search/query/merge.rb

Instance Method Summary collapse

Instance Method Details

#merge(other_hash) ⇒ Object



7
8
9
# File 'lib/caoutsearch/search/query/merge.rb', line 7

def merge(other_hash)
  dup.merge!(other_hash)
end

#merge!(other_hash) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/caoutsearch/search/query/merge.rb', line 11

def merge!(other_hash)
  merged_hash = to_h.deep_merge(other_hash) do |key, this_val, other_val|
    if this_val.is_a?(Array) && other_val.is_a?(Array)
      (this_val + other_val).uniq
    elsif block_given?
      yield key, this_val, other_val
    else
      other_val
    end
  end

  super(merged_hash)
end