Module: G5AuthenticationClient::Configuration

Includes:
Configlet
Included in:
G5AuthenticationClient
Defined in:
lib/g5_authentication_client/configuration.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#loggerLogger

Returns the logger to use for debug messages (defaults to STDOUT).

Returns:

  • (Logger)

    the logger to use for debug messages (defaults to STDOUT)



88
89
90
# File 'lib/g5_authentication_client/configuration.rb', line 88

def logger
  @logger ||= Logger.new(STDOUT)
end

Class Method Details

.extended(base) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/g5_authentication_client/configuration.rb', line 22

def self.extended(base)
  # Default configuration - happens whether or not .configure is called
  base.config :g5_auth do
    default debug: 'false'
    default username: nil
    default password: nil
    default endpoint: DEFAULT_ENDPOINT
    default client_id: DEFAULT_CLIENT_ID
    default client_secret: DEFAULT_CLIENT_SECRET
    default redirect_uri: DEFAULT_REDIRECT_URI
    default authorization_code: nil
    default access_token: nil
    default allow_password_credentials: DEFAULT_ALLOW_PASSWORD_CREDENTIALS
  end
end

Instance Method Details

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

Configures this module through the given block. Default configuration options will be applied unless they are explicitly overridden in the block.

Examples:

Typical case utilizing defaults

G5AuthenticationClient.configure do |config|
  config.username = 'my_user'
  config.password = 'my_pass'
end

Overriding defaults

G5AuthenticationClient.configure do |config|
  config.username = 'my_user'
  config.password = 'my_pass'
  config.endpoint = 'http://my.endpoint.com'
end

Yields:

  • (_self)

    configures service connection options

Yield Parameters:

Returns:

See Also:



111
112
113
114
115
116
117
# File 'lib/g5_authentication_client/configuration.rb', line 111

def configure
  config :g5_auth do
    yield self
  end

  self
end

#debug?true, false

Returns true if debug logging is enabled; false otherwie.

Returns:

  • (true, false)

    true if debug logging is enabled; false otherwie.



80
81
82
# File 'lib/g5_authentication_client/configuration.rb', line 80

def debug?
  self[:debug] == 'true'
end

#optionsHash<Symbol,Object>

Create a hash of configuration options and their values.

Returns:

  • (Hash<Symbol,Object>)

    the options hash



123
124
125
126
127
# File 'lib/g5_authentication_client/configuration.rb', line 123

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

#resetObject

Resets this module’s configuration. Configuration options will be set to default values if they exist; otherwise, they will be set to nil.



135
136
137
138
# File 'lib/g5_authentication_client/configuration.rb', line 135

def reset
  VALID_CONFIG_OPTIONS.each { |opt| self.send("#{opt}=", nil) }
  self
end