class EzConfig
Constants
- PRODUCTION_REGEX
Public Class Methods
[](k)
click to toggle source
# File lib/ez_config.rb, line 15 def [](k) instance[k] end
configure(opt)
click to toggle source
# File lib/ez_config.rb, line 7 def configure(opt) @opt = opt end
instance()
click to toggle source
# File lib/ez_config.rb, line 11 def instance @instance ||= new (@opt || {}) end
new(opt={})
click to toggle source
# File lib/ez_config.rb, line 24 def initialize(opt={}) @env = opt[:env].to_s || ENV['RACK_ENV'] || ENV['RAILS_ENV'] @path = opt[:path] || "#{Dir.pwd}/config/app_config" @production_regex = opt[:production_regex] || PRODUCTION_REGEX end
to_hash()
click to toggle source
# File lib/ez_config.rb, line 19 def to_hash instance.to_hash end
Public Instance Methods
[](k)
click to toggle source
# File lib/ez_config.rb, line 30 def [](k) to_hash[k] end
config()
click to toggle source
# File lib/ez_config.rb, line 42 def config @config ||= files.inject({}) do |config, file| key = File.basename file, '.yml' yaml = YAML.load_file file val = yaml[@env] || yaml[default_env] raise NoConfigForEnv, "Environment #{@env} not found in #{file}" unless val config[key] = val config end end
Also aliased as: to_hash
default_env()
click to toggle source
# File lib/ez_config.rb, line 38 def default_env @env =~ @production_regex ? 'production' : 'non_production' end
files()
click to toggle source
# File lib/ez_config.rb, line 34 def files Dir.glob File.join(@path, '*.yml') end