Class: Matchd::Response

Inherits:
Object
  • Object
show all
Defined in:
lib/matchd/response.rb

Direct Known Subclasses

A, CNAME, MX, NS, PTR, SOA, SRV, TXT

Defined Under Namespace

Modules: Factory Classes: A, AAAA, CNAME, MX, NS, PTR, SOA, SRV, TXT

Constant Summary collapse

NotImplementedError =
Class.new(RuntimeError)

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ Response

Returns a new instance of Response.

Parameters:

  • options (Hash)

    (Mind the string keys!)

Options Hash (options):

  • "ttl" (Numeric)

    The Time-To-Live of the record (default: ‘Async::DNS::Transaction::DEFAULT_TTL` = 86400sec = 24h)

  • "name" (String)

    The absolute DNS name. Default is the question name.

  • "section" (String)

    The answer section. One of “answer”, “additional”, “authority” (default: “answer”)



19
20
21
22
23
24
25
26
27
# File 'lib/matchd/response.rb', line 19

def initialize(options)
  @resource_options = {}

  return unless options.is_a?(Hash)

  @resource_options[:ttl]     = options["ttl"] if options.key?("ttl")
  @resource_options[:name]    = options["name"] if options.key?("name")
  @resource_options[:section] = options["section"] if options.key?("section")
end

Instance Attribute Details

#resource_optionsObject (readonly)

Returns the value of attribute resource_options.



29
30
31
# File 'lib/matchd/response.rb', line 29

def resource_options
  @resource_options
end

Instance Method Details

#call(transaction) ⇒ Object



35
36
37
# File 'lib/matchd/response.rb', line 35

def call(transaction)
  transaction.add([resource], resource_options)
end

#resourceObject



31
32
33
# File 'lib/matchd/response.rb', line 31

def resource
  raise NotImplementedError
end

#valid?Boolean

Returns:

  • (Boolean)


39
40
41
42
43
44
# File 'lib/matchd/response.rb', line 39

def valid?
  # TODO: this needs to be more suffisticated
  resource && true
rescue ArgumentError
  false
end