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
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 |
.clear ⇒ Object
62 63 64 |
# File 'lib/voorhees/config.rb', line 62 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 |
# 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 |
.reset ⇒ Object
66 67 68 |
# File 'lib/voorhees/config.rb', line 66 def reset @configuration = defaults end |
.setup {|_self| ... } ⇒ Object
57 58 59 60 |
# File 'lib/voorhees/config.rb', line 57 def setup yield self nil end |
.to_hash ⇒ Object
45 46 47 |
# File 'lib/voorhees/config.rb', line 45 def to_hash configuration end |