Class: Junkfood::Settings
- Inherits:
-
Object
- Object
- Junkfood::Settings
- Includes:
- Singleton
- Defined in:
- lib/junkfood/settings.rb
Overview
A Global Settings Singleton class for Rails applications.
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
Class Method Summary collapse
-
.[](key) ⇒ Object
Looks up the configuration option.
-
.config ⇒ Hash
The singleton's configuration.
Instance Method Summary collapse
-
#initialize ⇒ Settings
constructor
Reads the settings.yml and settings_
.yml file for configuration options and merges them together.
Constructor Details
#initialize ⇒ Settings
Reads the settings.yml and settings_
36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/junkfood/settings.rb', line 36 def initialize file = "#{Rails.root}/config/settings.yml" env_file = "#{Rails.root}/config/settings_#{Rails.env}.yml" @config = {} if File.exist? file base_cfg = YAML.load File.read(file) @config.deep_merge! base_cfg if base_cfg.kind_of? Hash end if File.exist? env_file env_cfg = YAML.load File.read(env_file) @config.deep_merge! env_cfg if env_cfg.kind_of? Hash end end |
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
28 29 30 |
# File 'lib/junkfood/settings.rb', line 28 def config @config end |
Class Method Details
.[](key) ⇒ Object
Looks up the configuration option.
63 64 65 |
# File 'lib/junkfood/settings.rb', line 63 def self.[](key) config[key] end |
.config ⇒ Hash
Returns the singleton's configuration.
53 54 55 |
# File 'lib/junkfood/settings.rb', line 53 def self.config instance.config end |