Module: RSpreedly::Config
- Defined in:
- lib/rspreedly/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 RSpreedly::Config.xxx.
- .reset ⇒ Object
-
.setup {|_self| ... } ⇒ Object
Yields the configuration.
- .to_hash ⇒ Object
Class Method Details
.[](key) ⇒ Object
20 21 22 |
# File 'lib/rspreedly/config.rb', line 20 def [](key) configuration[key] end |
.[]=(key, val) ⇒ Object
24 25 26 |
# File 'lib/rspreedly/config.rb', line 24 def []=(key, val) configuration[key] = val end |
.clear ⇒ Object
61 62 63 |
# File 'lib/rspreedly/config.rb', line 61 def clear @configuration = {} end |
.configuration ⇒ Object
the configuration hash itself
7 8 9 |
# File 'lib/rspreedly/config.rb', line 7 def configuration @configuration ||= defaults end |
.defaults ⇒ Object
11 12 13 14 15 16 17 18 |
# File 'lib/rspreedly/config.rb', line 11 def defaults { :logger => defined?(RAILS_DEFAULT_LOGGER) ? RAILS_DEFAULT_LOGGER : Logger.new(STDOUT), :debug => false, :site_name => "your-site-name", :api_key => "your-api-key" } end |
.delete(key) ⇒ Object
remove an item from the configuration
29 30 31 |
# File 'lib/rspreedly/config.rb', line 29 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
RSpreedly::Config.fetch(:monkey, false)
> false
40 41 42 |
# File 'lib/rspreedly/config.rb', line 40 def fetch(key, default) configuration.fetch(key, default) end |
.method_missing(method, *args) ⇒ Object
allow getting and setting properties via RSpreedly::Config.xxx
Examples
RSpreedly::Config.debug RSpreedly::Config.debug = false
75 76 77 78 79 80 81 82 |
# File 'lib/rspreedly/config.rb', line 75 def method_missing(method, *args) if method.to_s[-1,1] == '=' # splat with 1 item is just the item in 1.8, but an array in 1.9 configuration[method.to_s.tr('=','').to_sym] = args.is_a?(Array) ? args.first : args else configuration[method] end end |
.reset ⇒ Object
65 66 67 |
# File 'lib/rspreedly/config.rb', line 65 def reset @configuration = defaults end |
.setup {|_self| ... } ⇒ Object
56 57 58 59 |
# File 'lib/rspreedly/config.rb', line 56 def setup yield self nil end |
.to_hash ⇒ Object
44 45 46 |
# File 'lib/rspreedly/config.rb', line 44 def to_hash configuration end |