Module: Hashie::Extensions::DeepMergeConcat

Included in:
Orchparty::AST::Node, Orchparty::Context
Defined in:
lib/deep_merge.rb

Instance Method Summary collapse

Instance Method Details

#deep_merge_concat(other_hash) ⇒ Object

Returns a new hash with self and other_hash merged recursively.



64
65
66
67
68
# File 'lib/deep_merge.rb', line 64

def deep_merge_concat(other_hash, &)
  copy = dup
  copy.extend(Hashie::Extensions::DeepMergeConcat) unless copy.respond_to?(:deep_merge_concat!)
  copy.deep_merge_concat!(other_hash, &)
end

#deep_merge_concat!(other_hash) ⇒ Object

Returns a new hash with self and other_hash merged recursively. Modifies the receiver in place.



72
73
74
75
76
77
# File 'lib/deep_merge.rb', line 72

def deep_merge_concat!(other_hash, &)
  return self unless other_hash.is_a?(::Hash)

  _recursive_merge_concat(self, other_hash, &)
  self
end

#deep_sortObject

Returns a new hash with self and other_hash merged recursively.



50
51
52
53
54
# File 'lib/deep_merge.rb', line 50

def deep_sort(&)
  copy = dup
  copy.extend(Hashie::Extensions::DeepMergeConcat) unless copy.respond_to?(:deep_sort!)
  copy.deep_sort!(&)
end

#deep_sort!Object

Returns a new hash with self and other_hash merged recursively. Modifies the receiver in place.



58
59
60
61
# File 'lib/deep_merge.rb', line 58

def deep_sort!(&)
  _recursive_sort(self, &)
  self
end

#deep_sort_by_key_and_sort_array(exclusions = []) ⇒ Object



35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/deep_merge.rb', line 35

def deep_sort_by_key_and_sort_array(exclusions = [], &)
  keys.sort(&).each_with_object({}) do |key, seed|
    seed[key] = self[key]
    next if exclusions.include?(key.to_s)

    case seed[key]
    when Hash
      seed[key] = seed[key].deep_sort_by_key_and_sort_array(exclusions, &)
    when Hashie::Array
      seed[key] = seed[key].sort(&)
    end
  end
end

#deep_transform_valuesObject



79
80
81
# File 'lib/deep_merge.rb', line 79

def deep_transform_values(&)
  _deep_transform_values_in_object(self, &)
end

#deep_transform_values!Object



83
84
85
# File 'lib/deep_merge.rb', line 83

def deep_transform_values!(&)
  _deep_transform_values_in_object!(self, &)
end

#transform_keysObject



20
21
22
23
24
25
26
# File 'lib/deep_merge.rb', line 20

def transform_keys
  result = self.class.new
  each_key do |key|
    result[yield(key)] = self[key]
  end
  result
end

#transform_keys!Object



28
29
30
31
32
33
# File 'lib/deep_merge.rb', line 28

def transform_keys!
  keys.each do |key|
    self[yield(key)] = delete(key)
  end
  self
end

#transform_valuesObject



6
7
8
9
10
11
12
# File 'lib/deep_merge.rb', line 6

def transform_values
  result = self.class.new
  each do |key, value|
    result[key] = yield(value)
  end
  result
end

#transform_values!Object



14
15
16
17
18
# File 'lib/deep_merge.rb', line 14

def transform_values!
  each do |key, value|
    self[key] = yield(value)
  end
end