Module: Capgun::Config

Included in:
Capgun
Defined in:
lib/capgun/config.rb

Overview

Defines constants and methods related to configuration

Constant Summary collapse

DEFAULT_ADAPTER =

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

:net_http
DEFAULT_CONNECTION_OPTIONS =

The Faraday connection options if none is set

{}
DEFAULT_ENDPOINT =

API endpoint

'https://api.capgun.io'
DEFAULT_GATEWAY =

The gateway server if none is set

nil
DEFAULT_AUTH_TOKEN =

The auth token if none is set

""
DEFAULT_USER_AGENT =

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

"Capgun.io Ruby Gem #{Capgun::Version}"
DEFAULT_PROXY =

The proxy server if none is set

nil
VALID_OPTIONS_KEYS =

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

[
  :adapter,
  :connection_options,
  :endpoint,
  :gateway,
  :auth_token,
  :user_agent,
  :proxy,
]

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



43
44
45
# File 'lib/capgun/config.rb', line 43

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:



48
49
50
51
# File 'lib/capgun/config.rb', line 48

def configure
  yield self
  self
end

#optionsObject

Create a hash of options and their values



54
55
56
57
58
# File 'lib/capgun/config.rb', line 54

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

#resetObject

Reset all configuration options to defaults



61
62
63
64
65
66
67
68
69
70
# File 'lib/capgun/config.rb', line 61

def reset
  self.adapter            = DEFAULT_ADAPTER
  self.connection_options = DEFAULT_CONNECTION_OPTIONS
  self.endpoint           = DEFAULT_ENDPOINT
  self.gateway            = DEFAULT_GATEWAY
  self.auth_token         = DEFAULT_AUTH_TOKEN
  self.user_agent         = DEFAULT_USER_AGENT
  self.proxy              = DEFAULT_PROXY
  self
end