Module: TPEX::Configuration

Included in:
TPEX
Defined in:
lib/tpex/configuration.rb

Constant Summary collapse

VALID_OPTIONS_KEYS =
[
	:username,
	:password,
	:access_token,
	:endpoint,
       :access_endpoint,
	:format,
	:user_agent,
	:cookie,
       :logging
].freeze
VALID_FORMATS =
[
  :json
].freeze
DEFAULT_FORMAT =

Default config values

:json
DEFAULT_USERNAME =
nil
DEFAULT_PASSWORD =
nil
DEFAULT_ACCESS_TOKEN =
nil
DEFAULT_ENDPOINT =
'http://aw.concept3ddev.com/tpex/test_endpoint'
DEFAULT_USER_AGENT =
"TPEX Ruby Client #{TPEX::VERSION}".freeze
nil
DEFAULT_LOGGING =
nil

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



36
37
38
# File 'lib/tpex/configuration.rb', line 36

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:



41
42
43
# File 'lib/tpex/configuration.rb', line 41

def configure
  yield self
end

#optionsObject

Create a hash of options and their values



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

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

#resetObject

Reset all configuration options to defaults



53
54
55
56
57
58
59
60
61
62
# File 'lib/tpex/configuration.rb', line 53

def reset
 self.format = DEFAULT_FORMAT
 self.username = DEFAULT_USERNAME
 self.password = DEFAULT_PASSWORD
 self.access_token = DEFAULT_ACCESS_TOKEN
 self.endpoint = DEFAULT_ENDPOINT
 self.user_agent = DEFAULT_USER_AGENT
 self.cookie = DEFAULT_COOKIE
    self.logging = DEFAULT_LOGGING
end