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,
       :roles,
       :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://tp-dev.development.nrel.gov/api/'
DEFAULT_USER_AGENT =
"TPEX Ruby Client #{TPEX::VERSION}".freeze
nil
DEFAULT_ROLES =
['Authenticated']
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



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

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:



45
46
47
# File 'lib/tpex/configuration.rb', line 45

def configure
  yield self
end

#optionsObject

Create a hash of options and their values



50
51
52
53
54
# File 'lib/tpex/configuration.rb', line 50

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

#resetObject

Reset all configuration options to defaults



57
58
59
60
61
62
63
64
65
66
67
# File 'lib/tpex/configuration.rb', line 57

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.roles = DEFAULT_ROLES
    self.logging = DEFAULT_LOGGING
end