Module: DPN::Client::Agent::Configuration

Included in:
DPN::Client::Agent
Defined in:
lib/dpn/client/agent/configuration.rb

Defined Under Namespace

Classes: NullLogger

Constant Summary collapse

@@keys =
[
    :api_root, :auth_token,
    :per_page, :user_agent,
    :logger
]
@@defaults =
{
    api_root: nil.freeze,
    auth_token: nil.freeze,
    per_page: 25.freeze,
    user_agent: "dpn-client".freeze
}.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#api_rootObject

Returns the value of attribute api_root.



25
26
27
# File 'lib/dpn/client/agent/configuration.rb', line 25

def api_root
  @api_root
end

#auth_tokenObject

Returns the value of attribute auth_token.



25
26
27
# File 'lib/dpn/client/agent/configuration.rb', line 25

def auth_token
  @auth_token
end

#loggerObject



61
62
63
# File 'lib/dpn/client/agent/configuration.rb', line 61

def logger
  @logger ||= NullLogger.new
end

#per_pageObject

Returns the value of attribute per_page.



25
26
27
# File 'lib/dpn/client/agent/configuration.rb', line 25

def per_page
  @per_page
end

#user_agentObject

Returns the value of attribute user_agent.



25
26
27
# File 'lib/dpn/client/agent/configuration.rb', line 25

def user_agent
  @user_agent
end

Instance Method Details

#api_verObject



29
30
31
# File 'lib/dpn/client/agent/configuration.rb', line 29

def api_ver
  @api_ver ||= "api-v#{DPN::Client.api_version}"
end

#base_urlObject



33
34
35
# File 'lib/dpn/client/agent/configuration.rb', line 33

def base_url
  @api_root
end

#configure(options_hash = {}) ⇒ Object

Apply the options hash to the configuration



38
39
40
41
42
43
44
45
46
47
48
# File 'lib/dpn/client/agent/configuration.rb', line 38

def configure(options_hash = {})
  keys.each do |key|
    if options_hash[key]
      instance_variable_set(:"@#{key}", options_hash[key])
    end
  end
  if block_given?
    yield self
  end
  return self
end

#resetObject Also known as: setup

Reset to default values



52
53
54
55
56
57
# File 'lib/dpn/client/agent/configuration.rb', line 52

def reset
  keys.each do |key|
    instance_variable_set(:"@#{key}", defaults[key])
    self
  end
end