Module: Shirtsio::Configuration

Included in:
Shirtsio
Defined in:
lib/shirtsio/configuration.rb

Overview

Defines constants and methods related to configuration.

Constant Summary collapse

VALID_OPTIONS_KEYS =
[
  :api_key,
  :endpoint,
  :proxy,
  :user_agent
].freeze
DEFAULT_API_KEY =

By default, don’t set API key.

nil.freeze
DEFAULT_ENDPOINT =

The endpoint that will be used to authorize a user if none is set.

'https://www.shirts.io/api/v1'.freeze
DEFAULT_PROXY =

By default, don’t set a proxy server

nil.freeze
DEFAULT_USER_AGENT =

The user agent that will be sent to the API endpoint if none is set.

"shirtsio gem v#{Shirtsio::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.



28
29
30
# File 'lib/shirtsio/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:



34
35
36
# File 'lib/shirtsio/configuration.rb', line 34

def configure
  yield self
end

#optionsObject

Create a hash of options and their values.



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

def options
  VALID_OPTIONS_KEYS.inject({}) do |option, key|
    option.merge!(key => send(key))
  end
end

#resetObject

Reset all configuration options to default.



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

def reset
  self.api_key = DEFAULT_API_KEY
  self.endpoint = DEFAULT_ENDPOINT
  self.proxy = DEFAULT_PROXY
  self.user_agent = DEFAULT_USER_AGENT
end