Module: Roe::Configuration

Included in:
Roe
Defined in:
lib/roe/configuration.rb

Overview

Defines constants and methods related to configuration

Constant Summary collapse

VALID_OPTIONS_KEYS =

An array of valid keys in the options hash on configuration

[
:adapter,
:proxy,
:user_agent,
:connection_options].freeze
DEFAULT_ADAPTER =

The adapter that will be used to connect if none is set

:net_http
DEFAULT_PROXY =

By default, don't use a proxy server

nil
DEFAULT_USER_AGENT =

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

"Roe Ruby Gem #{Roe::VERSION}".freeze
DEFAULT_CONNECTION_OPTIONS =
{}.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



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

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:



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

def configure
  yield self
end

#optionsObject

Create a hash of options and their values



38
39
40
41
42
# File 'lib/roe/configuration.rb', line 38

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

#resetObject

Reset all configuration options to defaults



45
46
47
48
49
50
51
# File 'lib/roe/configuration.rb', line 45

def reset
  self.adapter            = DEFAULT_ADAPTER
  self.proxy              = DEFAULT_PROXY
  self.user_agent         = DEFAULT_USER_AGENT
  self.connection_options = DEFAULT_CONNECTION_OPTIONS
  self
end