Module: Voorhees::Config

Defined in:
lib/voorhees/config.rb

Class Method Summary collapse

Class Method Details

.[](key) ⇒ Object



22
23
24
# File 'lib/voorhees/config.rb', line 22

def [](key)
  configuration[key]
end

.[]=(key, val) ⇒ Object



26
27
28
# File 'lib/voorhees/config.rb', line 26

def []=(key, val)
  configuration[key] = val
end

.clearObject



63
64
65
# File 'lib/voorhees/config.rb', line 63

def clear
  @configuration = {}
end

.configurationObject

the configuration hash itself



8
9
10
# File 'lib/voorhees/config.rb', line 8

def configuration
  @configuration ||= defaults
end

.defaultsObject



12
13
14
15
16
17
18
19
20
# File 'lib/voorhees/config.rb', line 12

def defaults
  {
    :logger              => defined?(RAILS_DEFAULT_LOGGER) ? RAILS_DEFAULT_LOGGER : Logger.new(STDOUT),
    :timeout             => 10,
    :retries             => 0,
    :http_method         => Net::HTTP::Get,
    :response_class      => Voorhees::Response
  }
end

.delete(key) ⇒ Object

remove an item from the configuration



31
32
33
# File 'lib/voorhees/config.rb', line 31

def delete(key)
  configuration.delete(key)
end

.fetch(key, default) ⇒ Object

Return the value of the key, or the default if doesn’t exist

Examples

Voorhees::Config.fetch(:monkey, false)

> false



42
43
44
# File 'lib/voorhees/config.rb', line 42

def fetch(key, default)
  configuration.fetch(key, default)
end

.method_missing(method, *args) ⇒ Object

allow getting and setting properties via Voorhees::Config.xxx

Examples

Voorhees::Config.debug Voorhees::Config.debug = false



77
78
79
80
81
82
83
# File 'lib/voorhees/config.rb', line 77

def method_missing(method, *args)
  if method.to_s[-1,1] == '='
    configuration[method.to_s.tr('=','').to_sym] = *args
  else
    configuration[method]
  end
end

.resetObject



67
68
69
# File 'lib/voorhees/config.rb', line 67

def reset
  @configuration = defaults
end

.setup {|_self| ... } ⇒ Object

Yields the configuration.

Examples

Voorhees::Config.use do |config|
  config[:debug]    = true
  config.something  = false
end

Yields:

  • (_self)

Yield Parameters:



58
59
60
61
# File 'lib/voorhees/config.rb', line 58

def setup
  yield self
  nil
end

.to_hashObject



46
47
48
# File 'lib/voorhees/config.rb', line 46

def to_hash
  configuration
end