module Configuration

Constants

VERSION

Attributes

root[RW]

Public Class Methods

env() click to toggle source
# File lib/configuration.rb, line 35
def env
  @env ||= (ENV["RACK_ENV"] || Rails.env).to_sym rescue nil
end
files() click to toggle source
# File lib/configuration.rb, line 31
def files
  @files ||= Dir.glob(files_path)
end
method_missing(method, *args) click to toggle source
# File lib/configuration.rb, line 25
def method_missing(method, *args)
  if file = files.select { |f| f == files_path(method.to_s) }[0]
    hash[method] ||= load_yml(file)
  end
end

Private Class Methods

files_path(filename="*") click to toggle source
# File lib/configuration.rb, line 41
def files_path(filename="*")
  root.nil? ? "config/#{filename}.yml" : File.join(root, "config/#{filename}.yml")
end
hash() click to toggle source
# File lib/configuration.rb, line 45
def hash
  @hash ||= {}
end
load_yml(file) click to toggle source
# File lib/configuration.rb, line 49
def load_yml(file)
  config = with_symbol_keys YAML.load_file(file)
  config.is_a?(Hash) && config.has_key?(env) ?
    config[env] : config
end
with_symbol_keys(hash_config) click to toggle source
# File lib/configuration.rb, line 55
def with_symbol_keys(hash_config)
  return hash_config unless hash_config.is_a?(Hash)

  hash_config.inject({}) do |symbolized, (key, value)|
    symbolized.merge({ key.to_sym => with_symbol_keys(value), key => value })
  end
end