Module: Controls::Configurable

Included in:
Controls, Client
Defined in:
lib/controls/configurable.rb

Overview

A module to hold configurable options to be used by other classes such as the Controls eigenclass or the Client class

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#api_endpointString

Returns the endpoint to connect to. default: nexpose.local:3780/insight/controls/api/1.0.

Returns:



25
26
27
# File 'lib/controls/configurable.rb', line 25

def api_endpoint
  @api_endpoint
end

#api_versionObject

Returns the value of attribute api_version.



25
26
27
# File 'lib/controls/configurable.rb', line 25

def api_version
  @api_version
end

#connection_optionsHash

Returns the current connection options (headers, etc.).

Returns:

  • (Hash)

    the current connection options (headers, etc.)



25
26
27
# File 'lib/controls/configurable.rb', line 25

attr_accessor :api_endpoint, :api_version, :connection_options,
:default_media_type, :middleware, :netrc, :netrc_file,
:user_agent, :username, :web_endpoint

#default_media_typeString

Returns the default media type to send with requests. default: application/json.

Returns:

  • (String)

    the default media type to send with requests. default: application/json



25
26
27
# File 'lib/controls/configurable.rb', line 25

attr_accessor :api_endpoint, :api_version, :connection_options,
:default_media_type, :middleware, :netrc, :netrc_file,
:user_agent, :username, :web_endpoint

#middlewareFaraday::Connection

Returns the middleware used to send requests.

Returns:

  • (Faraday::Connection)

    the middleware used to send requests



25
26
27
# File 'lib/controls/configurable.rb', line 25

attr_accessor :api_endpoint, :api_version, :connection_options,
:default_media_type, :middleware, :netrc, :netrc_file,
:user_agent, :username, :web_endpoint

#netrcBoolean

Returns whether to use the netrc credentials to authentcicate with the **controls**insight API.

Returns:

  • (Boolean)

    whether to use the netrc credentials to authentcicate with the **controls**insight API



25
26
27
# File 'lib/controls/configurable.rb', line 25

attr_accessor :api_endpoint, :api_version, :connection_options,
:default_media_type, :middleware, :netrc, :netrc_file,
:user_agent, :username, :web_endpoint

#netrc_fileString

Returns the path of the .netrc file to look for credentials in. default: ~/.netrc.

Returns:

  • (String)

    the path of the .netrc file to look for credentials in. default: ~/.netrc



25
26
27
# File 'lib/controls/configurable.rb', line 25

attr_accessor :api_endpoint, :api_version, :connection_options,
:default_media_type, :middleware, :netrc, :netrc_file,
:user_agent, :username, :web_endpoint

#password=(value) ⇒ Object (writeonly)

Sets the attribute password

Parameters:

  • value

    the value to set the attribute password to.



31
32
33
# File 'lib/controls/configurable.rb', line 31

def password=(value)
  @password = value
end

#user_agentString

Returns the user agent to send with API requests. example: “controls/v1.0.0.beta (ruby; 2.0.0p247; [x86_64-darwin12.4.0]; Faraday v0.8.8)”.

Returns:

  • (String)

    the user agent to send with API requests. example: “controls/v1.0.0.beta (ruby; 2.0.0p247; [x86_64-darwin12.4.0]; Faraday v0.8.8)”



25
26
27
# File 'lib/controls/configurable.rb', line 25

attr_accessor :api_endpoint, :api_version, :connection_options,
:default_media_type, :middleware, :netrc, :netrc_file,
:user_agent, :username, :web_endpoint

#usernameString

Returns the username to use for authentication.

Returns:

  • (String)

    the username to use for authentication



25
26
27
# File 'lib/controls/configurable.rb', line 25

attr_accessor :api_endpoint, :api_version, :connection_options,
:default_media_type, :middleware, :netrc, :netrc_file,
:user_agent, :username, :web_endpoint

#web_endpointString

Returns the endpoint to connect to. default: nexpose.local:3780/insight/controls.

Returns:



25
26
27
# File 'lib/controls/configurable.rb', line 25

attr_accessor :api_endpoint, :api_version, :connection_options,
:default_media_type, :middleware, :netrc, :netrc_file,
:user_agent, :username, :web_endpoint

Class Method Details

.keysArray<Symbol>

Returns a list of configurable keys.

Returns:

  • (Array<Symbol>)

    a list of configurable keys



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/controls/configurable.rb', line 35

def keys
  @keys ||= [
    :api_endpoint,
    :api_version,
    :connection_options,
    :default_media_type,
    :middleware,
    :netrc,
    :netrc_file,
    :password,
    :user_agent,
    :username,
    :web_endpoint
  ]
end

Instance Method Details

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

Yields:

  • (self)


53
54
55
# File 'lib/controls/configurable.rb', line 53

def configure
  yield self
end

#netrc?Boolean

Returns:

  • (Boolean)


57
58
59
# File 'lib/controls/configurable.rb', line 57

def netrc?
  !!@netrc
end

#setupself

Configures Controls::Configurable to use options found in Default

Returns:

  • (self)


65
66
67
68
69
70
71
# File 'lib/controls/configurable.rb', line 65

def setup
  Controls::Configurable.keys.each do |key|
    instance_variable_set(:"@#{key}", Controls::Default.options[key])
  end

  self
end