Class: PDNS::Config

Inherits:
API
  • Object
show all
Defined in:
lib/pdns_api/config.rb

Overview

Configuration option for a DNS Server.

Instance Attribute Summary collapse

Attributes inherited from API

#class, #url

Instance Method Summary collapse

Methods inherited from API

#create, #ensure_array, #info

Constructor Details

#initialize(http, parent, name, value = nil) ⇒ Config

Creates a configuration option object.

Parameters:

  • http (HTTP)

    An HTTP object for interaction with the PowerDNS server.

  • parent (API)

    This object's parent.

  • name (String)

    Name of the configuration option.

  • value (String) (defaults to: nil)

    Optional value of the configuration option.


40
41
42
43
44
45
46
47
48
# File 'lib/pdns_api/config.rb', line 40

def initialize(http, parent, name, value = nil)
  @class  = :config
  @http   = http
  @parent = parent
  @name   = name
  @url    = "#{parent.url}/#{@class}/#{name}"
  @value  = get if value.nil?
  value(@value)
end

Instance Attribute Details

#nameString

Returns the name of the configuration option.

Returns:

  • (String)

    the name of the configuration option.


26
27
28
# File 'lib/pdns_api/config.rb', line 26

def name
  @name
end

Instance Method Details

#change(value = nil) ⇒ Hash

Changes this object's information on the server.

Examples:

config = server.config('version')
config.change('PowerDNS v3.14159265')

Parameters:

  • value (String, nil) (defaults to: nil)

    Value to change the object to.

    • If value is set, the current value is used.

    • If value is not set, value is updated and then used.

Returns:

  • (Hash)

    result of the change.


88
89
90
91
# File 'lib/pdns_api/config.rb', line 88

def change(value = nil)
  value(value)
  @http.put(@url, @info)
end

#deleteObject

Disabled common methods


30
# File 'lib/pdns_api/config.rb', line 30

undef_method :delete

#getHash

Gets the current information. This also updates value.

Returns:

  • (Hash)

    the object's information from the API.


69
70
71
72
73
# File 'lib/pdns_api/config.rb', line 69

def get
  res = @http.get @url
  value(res[:value]) if res.key? :value
  res
end

#value(value = nil) ⇒ String

Gets or sets the value attribute.

Parameters:

  • value (String, nil) (defaults to: nil)

    the value of the object.

Returns:

  • (String)

    the value of the object. If value is set the object's value is updated.


57
58
59
60
61
# File 'lib/pdns_api/config.rb', line 57

def value(value = nil)
  return @value if value.nil?
  @info  = { type: 'ConfigSetting', name: @name, value: value }
  @value = value
end