Module: RSpreedly::Config

Defined in:
lib/rspreedly/config.rb

Class Method Summary collapse

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

.clearObject



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

def clear
  @configuration = {}
end

.configurationObject

the configuration hash itself



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

def configuration
  @configuration ||= defaults
end

.defaultsObject



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

.resetObject



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

def reset
  @configuration = defaults
end

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

Yields the configuration.

Examples

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

Yields:

  • (_self)

Yield Parameters:



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

def setup
  yield self
  nil
end

.to_hashObject



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

def to_hash
  configuration
end