Class: DNS::ResolveHost

Inherits:
Object
  • Object
show all
Includes:
Log::Dependency
Defined in:
lib/dns/resolve_host/log.rb,
lib/dns/resolve_host/defaults.rb,
lib/dns/resolve_host/nameserver.rb,
lib/dns/resolve_host/substitute.rb,
lib/dns/resolve_host/resolve_host.rb,
lib/dns/resolve_host/controls/server.rb,
lib/dns/resolve_host/controls/hostname.rb,
lib/dns/resolve_host/controls/ip_address.rb

Defined Under Namespace

Modules: Controls, Defaults, LogAttributes, Substitute Classes: Log, Nameserver

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#nameserverObject

Returns the value of attribute nameserver.



7
8
9
# File 'lib/dns/resolve_host/resolve_host.rb', line 7

def nameserver
  @nameserver
end

Instance Method Details

#call(hostname, &block) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/dns/resolve_host/resolve_host.rb', line 9

def call(hostname, &block)
  if nameserver
    options = { :nameserver_port => [nameserver.to_a] }
  else
    options = nil
  end

  logger.trace { "Resolving host (#{LogAttributes.get self, hostname})" }

  Resolv::DNS.open options do |dns|
    block.(dns) if block

    addresses = dns.getaddresses hostname

    addresses.map! &:to_s

    if addresses.empty?
      logger.warn { "Could not resolve host (#{LogAttributes.get self, hostname})" }
    else
      logger.info { "Resolved host (#{LogAttributes.get self, hostname}, Address#{'es' unless addresses.count == 1}: #{addresses * ', '})" }
    end

    return addresses
  end
end