Module: Chargify::Config

Defined in:
lib/chargify/config.rb

Class Method Summary collapse

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

.clearObject



61
62
63
# File 'lib/chargify/config.rb', line 61

def clear
  @configuration = {}
end

.configurationObject

the configuration hash itself



7
8
9
# File 'lib/chargify/config.rb', line 7

def configuration
  @configuration ||= defaults
end

.defaultsObject



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

.resetObject



65
66
67
# File 'lib/chargify/config.rb', line 65

def reset
  @configuration = defaults
end

.setup {|_self| ... } ⇒ Object

Yields the configuration.

Examples

Chargify::Config.use do |config|
  config[:debug]    = true
  config.something  = false
end

Yields:

  • (_self)

Yield Parameters:



56
57
58
59
# File 'lib/chargify/config.rb', line 56

def setup
  yield self
  nil
end

.to_hashObject



44
45
46
# File 'lib/chargify/config.rb', line 44

def to_hash
  configuration
end