Module: AppEnvConfig

Defined in:
lib/app_env_config.rb,
lib/app_env_config/version.rb,
lib/generators/app_env_config/install_generator.rb

Defined Under Namespace

Modules: Generators

Constant Summary collapse

VERSION =
'0.1.2'
@@cache =
{}

Class Method Summary collapse

Class Method Details

.get(config_name, with_env = true) ⇒ Object



12
13
14
15
# File 'lib/app_env_config.rb', line 12

def get(config_name, with_env = true)
  @@cache[config_name] ||= {}
  @@cache[config_name][with_env] ||= uncached(config_name, with_env)
end

.root_pathObject



7
8
9
10
# File 'lib/app_env_config.rb', line 7

def root_path
  # ENV['BUNDLE_GEMFILE'].gsub(/\/Gemfile\z/, '')
  Rails.root || Pathname.new(ENV['RAILS_ROOT'] || Dir.pwd)
end

.uncached(config_name, with_env = true) ⇒ Object



17
18
19
20
21
22
23
24
25
# File 'lib/app_env_config.rb', line 17

def uncached(config_name, with_env = true)
  hash = YAML.load(ERB.new(File.read([root_path, 'config', "#{config_name}.yml"].join('/'))).result)

  default = hash && hash['default'] || {}

  hash = hash[Rails.env] if with_env && hash

  (hash ? default.deep_merge(hash) : default).with_indifferent_access
end