Class: Cerberus::Config
- Inherits:
-
Object
- Object
- Cerberus::Config
- Defined in:
- lib/cerberus/config.rb
Instance Method Summary collapse
- #[](*path) ⇒ Object
-
#initialize(app_name = nil, cli_options = {}) ⇒ Config
constructor
A new instance of Config.
- #inspect ⇒ Object
- #merge!(hash, overwrite = true) ⇒ Object
Constructor Details
#initialize(app_name = nil, cli_options = {}) ⇒ Config
Returns a new instance of Config.
7 8 9 10 11 12 13 14 |
# File 'lib/cerberus/config.rb', line 7 def initialize(app_name = nil, = {}) @config = HashWithIndifferentAccess.new if app_name merge!(YAML.load(ERB.new(IO.read(CONFIG_FILE)).result)) if test(?f, CONFIG_FILE) merge!(YAML.load(ERB.new(IO.read(HOME + "/config/#{app_name}.yml")).result)) end merge!() end |
Instance Method Details
#[](*path) ⇒ Object
16 17 18 19 20 21 22 23 |
# File 'lib/cerberus/config.rb', line 16 def [](*path) c = @config path.each{|p| c = c[p] return if c.nil? } c end |
#inspect ⇒ Object
35 36 37 |
# File 'lib/cerberus/config.rb', line 35 def inspect @config.inspect end |
#merge!(hash, overwrite = true) ⇒ Object
25 26 27 28 29 30 31 32 33 |
# File 'lib/cerberus/config.rb', line 25 def merge!(hash, overwrite = true) if overwrite @config.deep_merge!(hash) else d = HashWithIndifferentAccess.new(hash) d.deep_merge!(@config) @config = d end end |