Class: Aquatone::Resolver

Inherits:
Object
  • Object
show all
Defined in:
lib/aquatone/resolver.rb

Constant Summary collapse

TIMEOUT =
3.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ Resolver

Returns a new instance of Resolver.



7
8
9
10
11
# File 'lib/aquatone/resolver.rb', line 7

def initialize(options)
  @options = {
    :timeout => TIMEOUT
  }.merge(options)
end

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



3
4
5
# File 'lib/aquatone/resolver.rb', line 3

def options
  @options
end

Instance Method Details

#resolve(host) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
# File 'lib/aquatone/resolver.rb', line 13

def resolve(host)
  retried = false
  host    = "#{host}." unless host.end_with?(".")
  return (resolve_with_nameserver(host) || resolve_with_fallback_nameserver(host))
rescue
  if !retried
    retried = true
    retry
  end
  nil
end

#resource(host) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/aquatone/resolver.rb', line 25

def resource(host)
  resource = resource_with_nameserver(host,
    Resolv::DNS::Resource::IN::CNAME) ||
  resource_with_fallback_nameserver(host,
    Resolv::DNS::Resource::IN::CNAME)
  if !resource
    resource = resource_with_nameserver(host,
      Resolv::DNS::Resource::IN::A) ||
    resource_with_fallback_nameserver(host,
      Resolv::DNS::Resource::IN::A)
  end
  resource
end