Class: Configatron
- Includes:
- Singleton
- Defined in:
- lib/gems/configatron-2.1.5/lib/configatron/store.rb,
lib/gems/configatron-2.1.5/lib/configatron/errors.rb,
lib/gems/configatron-2.1.5/lib/configatron/configatron.rb
Defined Under Namespace
Classes: ProtectedParameter, Store
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
Constructor Details
#initialize ⇒ Configatron
:nodoc:
6 7 8 9 |
# File 'lib/gems/configatron-2.1.5/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/gems/configatron-2.1.5/lib/configatron/configatron.rb', line 12 def method_missing(sym, *args) @_store[@_namespace].send(sym, *args) end |
Instance Method Details
#reset! ⇒ Object
Removes ALL configuration parameters
17 18 19 |
# File 'lib/gems/configatron-2.1.5/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/gems/configatron-2.1.5/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
44 45 46 47 |
# File 'lib/gems/configatron-2.1.5/lib/configatron/configatron.rb', line 44 def temp_end @_store.delete(@_namespace) @_namespace = :default end |
#temp_start(options = nil) ⇒ Object
36 37 38 39 40 41 42 |
# File 'lib/gems/configatron-2.1.5/lib/configatron/configatron.rb', line 36 def temp_start( = nil) @_namespace = rand @_store[@_namespace] = @_store[:default].deep_clone if self.method_missing(:configure_from_hash, ) end end |