class Middleman::DnsResolver::HostsResolver
Use network name server to resolve ips and names
Attributes
Public Class Methods
Source
# 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
Public Instance Methods
Source
# 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
Get ips for name
@param [#to_s] name
The name to resolve into ips
@return [Array]
Array of ipaddresses
Source
# 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
Get names for ip
@param [#to_s] ip
The ip to resolve into names
@return [Array]
Array of Names
Private Instance Methods
Source
# File lib/middleman-core/dns_resolver/hosts_resolver.rb, line 56 def hosts_file return [ENV['MM_HOSTSRC']] if ENV.key?('MM_HOSTSRC') && File.file?(ENV['MM_HOSTSRC']) [] end
Path to hosts file
This looks for MM_HOSTSRC in your environment
@return [Array]
This needs to be an array, to make the splat operator work
@example
# <ip> <hostname> 127.0.0.1 localhost.localhost localhost