Class: Configatron
- Includes:
- Singleton
- Defined in:
- lib/configatron/proc.rb,
lib/configatron/rails.rb,
lib/configatron/store.rb,
lib/configatron/errors.rb,
lib/configatron/configatron.rb,
lib/generators/configatron/install/install_generator.rb
Defined Under Namespace
Modules: Rails Classes: Delayed, Dynamic, InstallGenerator, LockedNamespace, Proc, ProtectedParameter, Store
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize ⇒ Configatron
constructor
:nodoc:.
-
#method_missing(sym, *args, &block) ⇒ Object
Forwards the method call onto the ‘namespaced’ Configatron::Store.
-
#reset! ⇒ Object
Removes ALL configuration parameters.
-
#respond_to?(method) ⇒ Boolean
respond_to to respond_to.
-
#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:
23 24 25 26 |
# File 'lib/configatron/configatron.rb', line 23 def initialize # :nodoc: @_namespace = [:default] reset! end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(sym, *args, &block) ⇒ Object
Forwards the method call onto the ‘namespaced’ Configatron::Store
29 30 31 |
# File 'lib/configatron/configatron.rb', line 29 def method_missing(sym, *args, &block) @_store[@_namespace.last].send(sym, *args, &block) end |
Class Method Details
.log ⇒ Object
11 12 13 14 15 16 17 18 19 |
# File 'lib/configatron/configatron.rb', line 11 def log unless @logger if defined?(::Rails) @logger = ::Rails.logger end @logger = ::Logger.new(STDOUT) if @logger.nil? end return @logger end |
Instance Method Details
#reset! ⇒ Object
Removes ALL configuration parameters
39 40 41 |
# File 'lib/configatron/configatron.rb', line 39 def reset! @_store = {:default => Configatron::Store.new} end |
#respond_to?(method) ⇒ Boolean
respond_to to respond_to
34 35 36 |
# File 'lib/configatron/configatron.rb', line 34 def respond_to?(method) !@_store[@_namespace.last].send(method).nil? || super 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.
47 48 49 50 51 52 53 54 55 56 |
# File 'lib/configatron/configatron.rb', line 47 def temp( = nil) begin temp_start() yield @_store[@_namespace.last] rescue Exception => e raise e ensure temp_end end end |
#temp_end ⇒ Object
67 68 69 |
# File 'lib/configatron/configatron.rb', line 67 def temp_end @_store.delete(@_namespace.pop) end |
#temp_start(options = nil) ⇒ Object
58 59 60 61 62 63 64 65 |
# File 'lib/configatron/configatron.rb', line 58 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 |