Module: Blacklight::CoreExt::DeepMergeUnlessBlank

Defined in:
vendor/plugins/blacklight/lib/blacklight/core_ext.rb

Instance Method Summary (collapse)

Instance Method Details

- (Object) deep_merge_unless_blank(hash)

does what it says it does. Merges in values (recursively), but only replaces with values that are not blank (nil or empty strings)



9
10
11
12
13
14
15
16
17
18
19
20
# File 'vendor/plugins/blacklight/lib/blacklight/core_ext.rb', line 9

def deep_merge_unless_blank(hash)
  target = dup
  hash.each_pair do |key,value|
    if value.respond_to?(:each_pair) and self[key].respond_to?(:each_pair)
      target[key] = target[key].deep_merge_unless_blank(value)
      next
    end
    # only set or override if the target has the key, AND the hash's value is not blank
    target[key] = value unless (target[key] && (value.nil? || value.to_s.empty?))
  end
  target
end