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