module Hashr::EnvDefaults

Attributes

env_namespace[W]

Public Instance Methods

definition() click to toggle source
Calls superclass method
# File lib/hashr/env_defaults.rb, line 13
def definition
  deep_enverize(super)
end
env_namespace() click to toggle source
# File lib/hashr/env_defaults.rb, line 9
def env_namespace
  @env_namespace ||= []
end

Protected Instance Methods

deep_enverize(hash, nesting = env_namespace) click to toggle source
# File lib/hashr/env_defaults.rb, line 19
def deep_enverize(hash, nesting = env_namespace)
  hash.each do |key, value|
    nesting << key.to_s.upcase
    hash[key] = case value
    when Hash
      deep_enverize(value, nesting)
    else
      ENV.fetch(nesting.join('_'), value)
    end.tap { nesting.pop }
  end
end