Module: Voorhees::Config

Defined in:
lib/voorhees/config.rb

Class Method Summary collapse

Class Method Details

.[](key) ⇒ Object



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

def [](key)
  configuration[key]
end

.[]=(key, val) ⇒ Object



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

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

.clearObject



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

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
# 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
  }
end

.delete(key) ⇒ Object

remove an item from the configuration



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

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



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

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



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

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



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

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:



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

def setup
  yield self
  nil
end

.to_hashObject



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

def to_hash
  configuration
end