Module: Voorhees::Config
- Defined in:
- lib/voorhees/config.rb
Class Method Summary collapse
- .[](key) ⇒ Object
- .[]=(key, val) ⇒ Object
- .clear ⇒ Object
-
.configuration ⇒ Object
the configuration hash itself.
- .defaults ⇒ Object
-
.delete(key) ⇒ Object
remove an item from the configuration.
-
.fetch(key, default) ⇒ Object
Return the value of the key, or the default if doesn’t exist.
-
.method_missing(method, *args) ⇒ Object
allow getting and setting properties via Voorhees::Config.xxx.
- .reset ⇒ Object
-
.setup {|_self| ... } ⇒ Object
Yields the configuration.
- .to_hash ⇒ Object
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 |
.clear ⇒ Object
63 64 65 |
# File 'lib/voorhees/config.rb', line 63 def clear @configuration = {} end |
.configuration ⇒ Object
the configuration hash itself
8 9 10 |
# File 'lib/voorhees/config.rb', line 8 def configuration @configuration ||= defaults end |
.defaults ⇒ Object
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 |
.reset ⇒ Object
67 68 69 |
# File 'lib/voorhees/config.rb', line 67 def reset @configuration = defaults end |
.setup {|_self| ... } ⇒ Object
58 59 60 61 |
# File 'lib/voorhees/config.rb', line 58 def setup yield self nil end |
.to_hash ⇒ Object
46 47 48 |
# File 'lib/voorhees/config.rb', line 46 def to_hash configuration end |