Module: Configurate::Provider

Defined in:
lib/configurate/provider.rb,
lib/configurate/provider/env.rb,
lib/configurate/provider/toml.rb,
lib/configurate/provider/yaml.rb,
lib/configurate/provider/dynamic.rb,
lib/configurate/provider/string_hash.rb

Defined Under Namespace

Classes: Base, Dynamic, Env, StringHash, TOML, YAML

Class Method Summary collapse

Class Method Details

.lookup_in_hash(setting_path, hash) { ... } ⇒ Object

Utility function to lookup a settings path in a hash

Parameters:

Yields:

  • fallback value if not found

Returns:

  • (Object)


24
25
26
27
28
29
30
31
32
# File 'lib/configurate/provider.rb', line 24

def self.lookup_in_hash setting_path, hash, &fallback
  fallback ||= proc { nil }
  while hash.is_a?(Hash) && hash.has_key?(setting_path.first) && !setting_path.empty?
    hash = hash[setting_path.shift]
  end
  return fallback.call unless setting_path.empty?

  hash
end