Module: App
- Defined in:
- lib/generators/app_yml/install/templates/app.rb
Overview
Public: An initializer that provides global access to the App constant (which holds all settings from config/app.yml).
Thanks to Adrian Danieli (sickpea.com/2009/6/rails-app-configuration-in-10-lines) for this idea.
Constant Summary collapse
- @@settings =
Initialize the settings hash
{}
Class Method Summary collapse
- .[](*args) ⇒ Object
-
.build_settings_hash ⇒ Object
Parses ‘config/app.yml’ and converts it into a HashWithIndifferentAccess (which provides us with dot syntax).
-
.method_missing(method, *args) ⇒ Object
Causes App.arg to call App.
Class Method Details
.[](*args) ⇒ Object
62 63 64 |
# File 'lib/generators/app_yml/install/templates/app.rb', line 62 def self.[](*args) args.inject(@@settings) { |hash, arg| hash[arg] } end |
.build_settings_hash ⇒ Object
Parses ‘config/app.yml’ and converts it into a HashWithIndifferentAccess (which provides us with dot syntax).
See ‘config/app.yml’ for examples.
69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/generators/app_yml/install/templates/app.rb', line 69 def self.build_settings_hash # Create a hash out of config/app.yml yaml = YAML.load(ERB.new(File.read(Rails.root.join('config', 'app.yml'))).result) # Fetch settings from the all: section @@settings = yaml['all'] # Merge in settings from the current environment's section, giving the environment's settings precedence @@settings.deep_update! yaml[Rails.env] || {} # Allow this hash's data to be accessed with both strings and symbols @@settings = HashWithIndifferentAccess.new @@settings end |