Class: AppKonfig::Config

Inherits:
Hash
  • Object
show all
Defined in:
lib/app_konfig/config.rb

Constant Summary collapse

DEFAULT_ENV =
'development'
CONFIG_PATH =
{
  public: './config/config.yml',
  secret: './config/secrets.yml',
}

Instance Method Summary collapse

Constructor Details

#initializeConfig

Returns a new instance of Config.



15
16
17
18
# File 'lib/app_konfig/config.rb', line 15

def initialize
  super
  deep_merge!(pub_config).deep_merge!(sec_config)
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(key) ⇒ Object



26
27
28
29
30
# File 'lib/app_konfig/config.rb', line 26

def method_missing(key)
  key = key.to_s
  return self[key] unless self[key].is_a?(Hash)
  ::AppKonfig::Config[self[key]]
end

Instance Method Details

#get(args) ⇒ Object



20
21
22
23
24
# File 'lib/app_konfig/config.rb', line 20

def get(args)
    args.split('.').inject(self) { |hash, arg| hash.fetch(arg) }
  rescue KeyError
    raise AppKonfig::ConfigurationKeyNotFound.new("configuration key not found")
end