Class: Configatron

Inherits:
Object show all
Includes:
Singleton
Defined in:
lib/configatron/proc.rb,
lib/configatron/rails.rb,
lib/configatron/store.rb,
lib/configatron/errors.rb,
lib/configatron/version.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

Constant Summary collapse

VERSION =
"2.12.0"

Class Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfigatron

:nodoc:



28
29
30
31
# File 'lib/configatron/configatron.rb', line 28

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



34
35
36
# File 'lib/configatron/configatron.rb', line 34

def method_missing(sym, *args, &block)
  @_store[@_namespace.last].send(sym, *args, &block)
end

Class Attribute Details

.strictObject

Returns the value of attribute strict.



11
12
13
# File 'lib/configatron/configatron.rb', line 11

def strict
  @strict
end

Class Method Details

.logObject



13
14
15
16
17
18
19
20
21
# File 'lib/configatron/configatron.rb', line 13

def log
  unless @logger
    if defined?(::Rails)
      @logger = ::Rails.logger
    end
    @logger = ::Logger.new(STDOUT) if @logger.nil?
  end
  return @logger
end

.reset!Object



23
24
25
# File 'lib/configatron/configatron.rb', line 23

def reset!
  @strict = false
end

Instance Method Details

#reset!Object

Removes ALL configuration parameters



44
45
46
47
# File 'lib/configatron/configatron.rb', line 44

def reset!
  self.class.reset!
  @_store = {:default => Configatron::Store.new}
end

#respond_to?(method) ⇒ Boolean

respond_to to respond_to

Returns:

  • (Boolean)


39
40
41
# File 'lib/configatron/configatron.rb', line 39

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.



53
54
55
56
57
58
59
60
61
62
# File 'lib/configatron/configatron.rb', line 53

def temp(options = nil)
  begin
    temp_start(options)
    yield @_store[@_namespace.last]
  rescue Exception => e
    raise e
  ensure
    temp_end
  end
end

#temp_endObject



73
74
75
# File 'lib/configatron/configatron.rb', line 73

def temp_end
  @_store.delete(@_namespace.pop)
end

#temp_start(options = nil) ⇒ Object



64
65
66
67
68
69
70
71
# File 'lib/configatron/configatron.rb', line 64

def temp_start(options = nil)
  n_space = rand
  @_store[n_space] = @_store[@_namespace.last].deep_clone
  @_namespace << n_space
  if options
    self.method_missing(:configure_from_hash, options)
  end
end