Class: Configue::Container
Overview
When you have such configuration files:
# config/accounts/admin_users.yml
accounts:
admin_users:
- grumpy
- sneezy
# config/accounts/test_users.yml
accounts:
test_users:
- sleepy
- dopey
you can load them into your class in the following ways:
class Foo < Configue::Container
config.source_dir "#{File.dirname(__FILE__)}/config"
end
Foo.accounts.admin_users
# => ["grumpy", "sneezy"]
Foo.accounts.test_users
# => ["sleepy", "dopey"]
Class Method Summary collapse
-
.config ⇒ Object
config
allows you to access the object for setting up container. -
.config_setting ⇒ Object
config_setting
is the same withconfig
.
Instance Method Summary collapse
-
#query(key = nil) ⇒ Object
When you do not know whether your setting object has keys that you want to specify and want to avoid
NoMethodError
, you can usequery
andretrieve
.
Methods inherited from Node
Constructor Details
This class inherits a constructor from Configue::Node
Class Method Details
.config ⇒ Object
config
allows you to access the object for setting up container.
56 57 58 59 |
# File 'lib/configue/container.rb', line 56 def config @config_access_name = "config" @setting ||= Setting.new(ContainerAdapter.new(self)) end |
.config_setting ⇒ Object
config_setting
is the same with config
.
62 63 64 65 |
# File 'lib/configue/container.rb', line 62 def config_setting @config_access_name = "config_setting" @setting ||= Setting.new(ContainerAdapter.new(self)) end |
Instance Method Details
#query(key = nil) ⇒ Object
When you do not know whether your setting object has keys that you want to specify and want to avoid NoMethodError
, you can use query
and retrieve
.
Foo.query("accounts.admin_users").retrieve
# => ["grumpy", "sneezy"]
Foo.query("users.admin_users").retrieve
# => nil
Foo.query[:accounts][:admin_users].retrieve
# => ["grumpy", "sneezy"]
48 49 50 51 52 |
# File 'lib/configue/container.rb', line 48 def query(key=nil) q = Criteria.new(self) q = key.split('.').each.inject(q) {|c, k| c[k] } if key q end |