Class: Middleman::DnsResolver::HostsResolver

Inherits:
Object
  • Object
show all
Defined in:
lib/middleman-core/dns_resolver/hosts_resolver.rb

Overview

Use network name server to resolve ips and names

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}) ⇒ HostsResolver

Returns a new instance of HostsResolver.



11
12
13
14
15
16
# File 'lib/middleman-core/dns_resolver/hosts_resolver.rb', line 11

def initialize(opts={})
  # using the splat operator works around a non-existing HOSTSRC variable
  # using nil as input does not work, but `*[]` does and then Resolv::Hosts
  # uses its defaults
  @resolver = opts.fetch(:resolver, Resolv::Hosts.new(*hosts_file))
end

Instance Method Details

#getaddresses(name) ⇒ Array

Get ips for name

Parameters:

  • name (#to_s)

    The name to resolve into ips

Returns:

  • (Array)

    Array of ipaddresses



38
39
40
41
42
# File 'lib/middleman-core/dns_resolver/hosts_resolver.rb', line 38

def getaddresses(name)
  resolver.getaddresses(name.to_s).map(&:to_s)
rescue Resolv::ResolvError
  []
end

#getnames(ip) ⇒ Array

Get names for ip

Parameters:

  • ip (#to_s)

    The ip to resolve into names

Returns:

  • (Array)

    Array of Names



25
26
27
28
29
# File 'lib/middleman-core/dns_resolver/hosts_resolver.rb', line 25

def getnames(ip)
  resolver.getnames(ip.to_s).map(&:to_s)
rescue Resolv::ResolvError
  []
end