Module: Gem::Release::Helper::Hash

Included in:
Cmds::Base, Config, Config::Env, Config::Files
Defined in:
lib/gem/release/helper/hash.rb

Constant Summary collapse

MERGER =
->(key, lft, rgt) do
  if lft.is_a?(::Hash) && rgt.is_a?(::Hash)
    lft.merge(rgt, &MERGER)
  else
    rgt
  end
end

Instance Method Summary collapse

Instance Method Details

#deep_merge(hash, other) ⇒ Object



13
14
15
# File 'lib/gem/release/helper/hash.rb', line 13

def deep_merge(hash, other)
  hash.merge(other, &MERGER)
end

#except(hash, *keys) ⇒ Object



29
30
31
# File 'lib/gem/release/helper/hash.rb', line 29

def except(hash, *keys)
  hash.reject { |key, _| keys.include?(key) }
end

#only(hash, *keys) ⇒ Object



25
26
27
# File 'lib/gem/release/helper/hash.rb', line 25

def only(hash, *keys)
  hash.select { |key, _| keys.include?(key) }
end

#symbolize_keys(hash) ⇒ Object



17
18
19
20
21
22
23
# File 'lib/gem/release/helper/hash.rb', line 17

def symbolize_keys(hash)
  hash.map do |key, obj|
    key = key.respond_to?(:to_sym) ? key.to_sym : key
    obj = symbolize_keys(obj) if obj.is_a?(::Hash)
    [key, obj]
  end.to_h
end