Class: Handy::ConfigLoader
- Inherits:
-
Object
- Object
- Handy::ConfigLoader
- Defined in:
- lib/handy/config_loader.rb
Instance Attribute Summary collapse
-
#filename ⇒ Object
readonly
Returns the value of attribute filename.
Instance Method Summary collapse
-
#initialize(filename) ⇒ ConfigLoader
constructor
A new instance of ConfigLoader.
- #load(key = Rails.env) ⇒ Object
Constructor Details
#initialize(filename) ⇒ ConfigLoader
Returns a new instance of ConfigLoader.
11 12 13 |
# File 'lib/handy/config_loader.rb', line 11 def initialize(filename) @filename = filename end |
Instance Attribute Details
#filename ⇒ Object (readonly)
Returns the value of attribute filename.
9 10 11 |
# File 'lib/handy/config_loader.rb', line 9 def filename @filename end |
Instance Method Details
#load(key = Rails.env) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/handy/config_loader.rb', line 15 def load(key = Rails.env) global_file = Rails.root.join('config', filename) settings = read_settings_from_file(global_file) common_settings = settings['common'] || {} env_settings = settings[key.to_s] || {} env_file = Rails.root.join('config', File.basename(filename, '.yml'), "#{key}.yml") env_settings_from_file = read_settings_from_file(env_file) env_settings = env_settings.deep_merge(env_settings_from_file) result_settings = common_settings.deep_merge(env_settings) ::Hashr.new(result_settings) end |