Module: Print::Configuration

Included in:
Print, Client
Defined in:
lib/print/configuration.rb

Constant Summary collapse

VALID_CONNECTION_KEYS =
[:endpoint, :user_agent, :method].freeze
VALID_OPTIONS_KEYS =
[:api_key, :format, :api_version].freeze
VALID_CONFIG_KEYS =
VALID_CONNECTION_KEYS + VALID_OPTIONS_KEYS
DEFAULT_ENDPOINT =
'http://print.dev/api'
DEFAULT_METHOD =
:get
DEFAULT_USER_AGENT =
"Print API Ruby Gem #{Print::VERSION}".freeze
DEFAULT_API_KEY =
nil
DEFAULT_FORMAT =
:json
DEFAULT_API_VERSION =
1

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.extended(base) ⇒ Object

Make sure we have the default values set when we get ‘extended’



20
21
22
# File 'lib/print/configuration.rb', line 20

def self.extended(base)
  base.reset
end

Instance Method Details

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

Yields:

  • (_self)

Yield Parameters:



24
25
26
# File 'lib/print/configuration.rb', line 24

def configure
  yield self
end

#optionsObject



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

def options
  Hash[ * VALID_CONFIG_KEYS.map { |key| [key, send(key)] }.flatten ]
end

#resetObject



32
33
34
35
36
37
38
39
40
# File 'lib/print/configuration.rb', line 32

def reset
  self.endpoint    = DEFAULT_ENDPOINT
  self.method      = DEFAULT_METHOD
  self.user_agent  = DEFAULT_USER_AGENT
 
  self.api_key     = DEFAULT_API_KEY
  self.format      = DEFAULT_FORMAT
  self.api_version = DEFAULT_API_VERSION
end