Class: Middleman::DnsResolver::HostsResolver
- Inherits:
-
Object
- Object
- Middleman::DnsResolver::HostsResolver
- Defined in:
- lib/middleman-core/dns_resolver/hosts_resolver.rb
Overview
Use network name server to resolve ips and names
Instance Method Summary collapse
-
#getaddresses(name) ⇒ Array
Get ips for name.
-
#getnames(ip) ⇒ Array
Get names for ip.
-
#initialize(opts = {}) ⇒ HostsResolver
constructor
A new instance of HostsResolver.
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
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
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 |