Module: ContextIO::Config

Included in:
ContextIO
Defined in:
lib/context-io/config.rb

Overview

Defines constants and methods related to configuration

You shouldn’t interact with this module directly, as it’s included in the ContextIO module. Mostly you’ll use the #configure method on ContextIO, see the example on #configure.

See Also:

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_CONSUMER_KEY =

The consumer key if none is set

nil
DEFAULT_CONSUMER_SECRET =

The consumer secret if none is set

nil
DEFAULT_PROXY =

The proxy server if none is set

nil
DEFAULT_USER_AGENT =

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

"context-io ruby gem #{ContextIO::VERSION}"
VALID_OPTIONS_KEYS =

The configuration options that are settable.

[
  :adapter,
  :connection_options,
  :consumer_key,
  :consumer_secret,
  :proxy,
  :user_agent
]

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#adapterSymbol



42
43
44
# File 'lib/context-io/config.rb', line 42

def adapter
  @adapter
end

#connection_optionsHash



45
46
47
# File 'lib/context-io/config.rb', line 45

def connection_options
  @connection_options
end

#consumer_keyString



48
49
50
# File 'lib/context-io/config.rb', line 48

def consumer_key
  @consumer_key
end

#consumer_secretString



51
52
53
# File 'lib/context-io/config.rb', line 51

def consumer_secret
  @consumer_secret
end

#proxyString, URI



54
55
56
# File 'lib/context-io/config.rb', line 54

def proxy
  @proxy
end

#user_agentString



59
60
61
# File 'lib/context-io/config.rb', line 59

def user_agent
  @user_agent
end

Class Method Details

.extended(base) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Makes sure the default values are always set



64
65
66
# File 'lib/context-io/config.rb', line 64

def self.extended(base)
  base.reset
end

Instance Method Details

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

Configure with a block

Examples:

Configuring OAuth

ContextIO.configure do |config|
  config.consumer_key = 'my_consumer_key'
  config.consumer_secret = 'my_consumer_secret'
end

Yields:

  • (_self)

Yield Parameters:



79
80
81
82
# File 'lib/context-io/config.rb', line 79

def configure
  yield self
  self
end

#resetvoid

This method returns an undefined value.

Reset the configuration to the default values

Examples:

Reset the configuration

ContextIO.adapter = :some_erroneous_thing
ContextIO.reset
ContextIO.adapter # => DEFAULT_ADAPTER


94
95
96
97
98
99
100
101
# File 'lib/context-io/config.rb', line 94

def reset
  self.adapter            = DEFAULT_ADAPTER
  self.connection_options = DEFAULT_CONNECTION_OPTIONS
  self.consumer_key       = DEFAULT_CONSUMER_KEY
  self.consumer_secret    = DEFAULT_CONSUMER_SECRET
  self.proxy              = DEFAULT_PROXY
  self.user_agent         = DEFAULT_USER_AGENT
end