Class: Configurate::Settings
- Inherits:
-
Object
- Object
- Configurate::Settings
- Extended by:
- Forwardable
- Defined in:
- lib/configurate.rb
Overview
This is your main entry point. Instead of lengthy explanations let an example demonstrate its usage:
require 'configuration_methods'
AppSettings = Configurate::Settings.create do
add_provider Configurate::Provider::Env
add_provider Configurate::Provider::YAML, '/etc/app_settings.yml',
namespace: Rails.env, required: false
add_provider Configurate::Provider::YAML, 'config/default_settings.yml'
extend YourConfigurationMethods
end
AppSettings.setup_something if AppSettings.something.enable?
Please also read the note at Proxy!
Instance Attribute Summary collapse
-
#lookup_chain ⇒ Object
readonly
Returns the value of attribute lookup_chain.
Class Method Summary collapse
-
.create { ... } ⇒ Object
Create a new configuration object.
Instance Method Summary collapse
-
#[](setting) ⇒ Object
(see LookupChain#[]).
-
#add_provider(provider, *args) ⇒ Object
(see LookupChain#add_provider).
-
#initialize ⇒ Settings
constructor
A new instance of Settings.
-
#lookup(setting) ⇒ Object
(see LookupChain#lookup).
-
#method_missing(method, *args, &block) ⇒ Object
See description and #lookup, #[] and #add_provider.
Constructor Details
#initialize ⇒ Settings
Returns a new instance of Settings.
44 45 46 47 |
# File 'lib/configurate.rb', line 44 def initialize @lookup_chain = LookupChain.new warn "Warning you called Configurate::Settings.new with a block, you really meant to call #create" if block_given? end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args, &block) ⇒ Object
See description and #lookup, #[] and #add_provider
61 62 63 |
# File 'lib/configurate.rb', line 61 def method_missing(method, *args, &block) Proxy.new(@lookup_chain).public_send(method, *args, &block) end |
Instance Attribute Details
#lookup_chain ⇒ Object (readonly)
Returns the value of attribute lookup_chain.
38 39 40 |
# File 'lib/configurate.rb', line 38 def lookup_chain @lookup_chain end |
Class Method Details
.create { ... } ⇒ Object
Create a new configuration object
67 68 69 70 71 |
# File 'lib/configurate.rb', line 67 def self.create(&block) config = new config.instance_eval(&block) if block_given? config end |
Instance Method Details
#[](setting) ⇒ Object
(see LookupChain#[])
58 |
# File 'lib/configurate.rb', line 58 def_delegators :@lookup_chain, :lookup, :add_provider, :[] |
#add_provider(provider, *args) ⇒ Object
(see LookupChain#add_provider)
|
# File 'lib/configurate.rb', line 52
|