Class: Configatron
- Inherits:
-
ConfigatronBlankSlate
- Object
- ConfigatronBlankSlate
- Configatron
- Includes:
- Singleton
- Defined in:
- lib/configatron/store.rb,
lib/configatron/errors.rb,
lib/configatron/configatron.rb
Defined Under Namespace
Classes: LockedNamespace, ProtectedParameter, Store
Constant Summary
Constants inherited from ConfigatronBlankSlate
ConfigatronBlankSlate::CONFIGATRON_WHITELIST
Instance Method Summary collapse
-
#initialize ⇒ Configatron
constructor
:nodoc:.
-
#method_missing(sym, *args) ⇒ Object
Forwards the method call onto the ‘namespaced’ Configatron::Store.
-
#reset! ⇒ Object
Removes ALL configuration parameters.
-
#temp(options = nil) ⇒ Object
Allows for the temporary overriding of parameters in a block.
- #temp_end ⇒ Object
- #temp_start(options = nil) ⇒ Object
Methods inherited from ConfigatronBlankSlate
find_hidden_method, hide, reveal
Constructor Details
#initialize ⇒ Configatron
:nodoc:
6 7 8 9 |
# File 'lib/configatron/configatron.rb', line 6 def initialize # :nodoc: @_namespace = [:default] reset! end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(sym, *args) ⇒ Object
Forwards the method call onto the ‘namespaced’ Configatron::Store
12 13 14 |
# File 'lib/configatron/configatron.rb', line 12 def method_missing(sym, *args) @_store[@_namespace.last].__send__(sym, *args) end |
Instance Method Details
#reset! ⇒ Object
Removes ALL configuration parameters
17 18 19 |
# File 'lib/configatron/configatron.rb', line 17 def reset! @_store = {:default => Configatron::Store.new} end |
#temp(options = nil) ⇒ Object
Allows for the temporary overriding of parameters in a block. Takes an optional Hash of parameters that will be applied before the block gets called. At the end of the block, the temporary settings are deleted and the original settings are reinstated.
25 26 27 28 29 30 31 32 33 34 |
# File 'lib/configatron/configatron.rb', line 25 def temp( = nil) begin temp_start() yield rescue Exception => e raise e ensure temp_end end end |
#temp_end ⇒ Object
45 46 47 |
# File 'lib/configatron/configatron.rb', line 45 def temp_end @_store.delete(@_namespace.pop) end |
#temp_start(options = nil) ⇒ Object
36 37 38 39 40 41 42 43 |
# File 'lib/configatron/configatron.rb', line 36 def temp_start( = nil) n_space = rand @_store[n_space] = @_store[@_namespace.last].deep_clone @_namespace << n_space if self.method_missing(:configure_from_hash, ) end end |