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.
8 9 10 |
# File 'lib/handy/config_loader.rb', line 8 def initialize(filename) @filename = filename end |
Instance Attribute Details
#filename ⇒ Object (readonly)
Returns the value of attribute filename.
6 7 8 |
# File 'lib/handy/config_loader.rb', line 6 def filename @filename end |
Instance Method Details
#load(key = Rails.env) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/handy/config_loader.rb', line 12 def load(key = Rails.env) file = Rails.root.join('config', filename) return unless File.exist?(file) hash = YAML.load(ERB.new(File.read(file)).result) common_hash = hash['common'] || {} env_hash = hash[key.to_s] || {} final_hash = common_hash.deep_merge(env_hash) ::Hashr.new(final_hash) end |