Class: Middleman::DnsResolver::HostsResolver

Inherits:
Object
  • Object
show all
Defined in:
middleman-core/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



11
12
13
14
15
16
# File 'middleman-core/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



38
39
40
41
42
# File 'middleman-core/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



25
26
27
28
29
# File 'middleman-core/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