Module: ParamsReady::Helpers::FindInHash

Defined in:
lib/params_ready/helpers/find_in_hash.rb

Class Method Summary collapse

Class Method Details

.find_in_hash(hash, name_or_path) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/params_ready/helpers/find_in_hash.rb', line 7

def self.find_in_hash(hash, name_or_path)
  return false, Extensions::Undefined if hash.nil?

  found = if name_or_path.is_a? Array
    *path, name = name_or_path
    Helpers::KeyMap::Mapping::Path.dig(name, hash, path)
  else
    Extensions::Hash.indifferent_access(hash, name_or_path, Extensions::Undefined)
  end

  return false, Extensions::Undefined if found == Extensions::Undefined
  return true, found
end