Module: Vibe::Configuration

Included in:
Vibe, Cache, Request
Defined in:
lib/vibe/configuration.rb

Constant Summary collapse

VALID_CONNECTION_KEYS =
[:endpoint, :user_agent, :method, :format].freeze
VALID_OPTIONS_KEYS =
[:api_key, :cache, :cache_driver].freeze
VALID_CONFIG_KEYS =
VALID_CONNECTION_KEYS + VALID_OPTIONS_KEYS
DEFAULT_ENDPOINT =
'https://z1.vibeapp.co/api/v1/'.freeze
DEFAULT_METHOD =
:get.freeze
DEFAULT_USER_AGENT =
"Vibe API Ruby Gem #{Vibe::VERSION}".freeze
DEFAULT_API_KEY =
nil
DEFAULT_FORMAT =
:json.freeze
DEFAULT_CACHE_DRIVER =
'FILE'.freeze
DEFAULT_CACHE =
true

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.extended(base) ⇒ Object

Make sure we have the default values set when we get ‘extended’



28
29
30
# File 'lib/vibe/configuration.rb', line 28

def self.extended(base)
  base.reset
end

Instance Method Details

#configure {|_self| ... } ⇒ Object

Setup Configuration

Yields:

  • (_self)

Yield Parameters:



33
34
35
# File 'lib/vibe/configuration.rb', line 33

def configure
  yield self
end

#optionsHash

Return the configuration values set in this module

Returns:

  • (Hash)


52
53
54
# File 'lib/vibe/configuration.rb', line 52

def options
  Hash[ * VALID_CONFIG_KEYS.map { |key| [key, send(key)] }.flatten ]
end

#resetObject

Reset config values to default



38
39
40
41
42
43
44
45
46
47
# File 'lib/vibe/configuration.rb', line 38

def reset
  self.endpoint     = DEFAULT_ENDPOINT
  self.method       = DEFAULT_METHOD
  self.user_agent   = DEFAULT_USER_AGENT
  self.format       = DEFAULT_FORMAT

  self.api_key      = DEFAULT_API_KEY
  self.cache_driver = DEFAULT_CACHE_DRIVER
  self.cache        = true
end