Module: Gems::Configuration

Included in:
Gems
Defined in:
lib/gems/configuration.rb

Constant Summary collapse

VALID_OPTIONS_KEYS =

An array of valid keys in the options hash when configuring a Gems::Client

[
  :format,
  :user_agent,
]
DEFAULT_FORMAT =
Note:

JSON is preferred over XML because it is more concise and faster to parse.

The response format appended to the path if none is set

:json
DEFAULT_USER_AGENT =

The value sent in the 'User-Agent' header if none is set

"Gems #{Gems::VERSION}".freeze

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.extended(base) ⇒ Object

When this module is extended, set all configuration options to their default values



22
23
24
# File 'lib/gems/configuration.rb', line 22

def self.extended(base)
  base.reset
end

Instance Method Details

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

Convenience method to allow configuration options to be set in a block

Yields:

  • (_self)

Yield Parameters:



27
28
29
# File 'lib/gems/configuration.rb', line 27

def configure
  yield self
end

#optionsObject

Create a hash of options and their values



32
33
34
35
36
# File 'lib/gems/configuration.rb', line 32

def options
  options = {}
  VALID_OPTIONS_KEYS.each{|k| options[k] = send(k)}
  options
end

#resetObject

Reset all configuration options to defaults



39
40
41
42
43
# File 'lib/gems/configuration.rb', line 39

def reset
  self.format     = DEFAULT_FORMAT
  self.user_agent = DEFAULT_USER_AGENT
  self
end