module Configurate::Provider

Public Class Methods

lookup_in_hash(setting_path, hash, &fallback) click to toggle source

Utility function to lookup a settings path in a hash @param setting_path [SettingPath] @param hash [Hash] @yield fallback value if not found @return [Object]

# 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