class FlexibleConfig::WrappedYaml

Constants

CONFIG_PATH

Public Class Methods

[](key) click to toggle source
# File lib/flexible_config/wrapped_yaml.rb, line 6
def [](key)
  environment_specific = get_config(key, env: app_environment)
  environment_specific.nil? ? get_config(key) : environment_specific
end
config_data() click to toggle source
# File lib/flexible_config/wrapped_yaml.rb, line 11
def config_data
  @config_data ||= Dir[CONFIG_PATH].reduce({}) do |memo, file|
    category = File.basename(file, '.yml')
    memo[category] = YAML.load File.open file
    memo
  end
end

Private Class Methods

app_environment() click to toggle source
# File lib/flexible_config/wrapped_yaml.rb, line 29
def app_environment
  (
    ENV['CONFIG_ENV'] ||
    ENV['RAILS_ENV']  ||
    ENV['RACK_ENV']   ||
    'development'
  )
end
get_config(key, env: 'default') click to toggle source
# File lib/flexible_config/wrapped_yaml.rb, line 21
def get_config(key, env: 'default')
  keys_with_injected_env = key.sub('.', ".#{env}.").split '.'

  keys_with_injected_env.reduce(config_data) do |memo, i|
    memo[i] unless memo.nil?
  end
end