Class: Middleman::DnsResolver
- Inherits:
-
Object
- Object
- Middleman::DnsResolver
- Defined in:
- lib/middleman-core/dns_resolver.rb,
lib/middleman-core/dns_resolver/hosts_resolver.rb,
lib/middleman-core/dns_resolver/network_resolver.rb,
lib/middleman-core/dns_resolver/local_link_resolver.rb,
lib/middleman-core/dns_resolver/basic_network_resolver.rb
Overview
This resolves IP address to names and vice versa
Defined Under Namespace
Classes: BasicNetworkResolver, HostsResolver, LocalLinkResolver, NetworkResolver
Instance Method Summary collapse
-
#initialize(opts = {}) ⇒ DnsResolver
constructor
Create resolver.
-
#ips_for(name) ⇒ Object
Get ips for given name.
-
#names_for(ip) ⇒ Object
Get names for given ip.
Constructor Details
#initialize(opts = {}) ⇒ DnsResolver
Create resolver
First the local resolver is used. If environment variable HOSTSRC is given this file is used for local name lookup.
First the local resolver is queried. If this raises an error or returns nil or [] the network resolver is queried.
30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/middleman-core/dns_resolver.rb', line 30 def initialize(opts={}) @resolvers = [] @resolvers << opts.fetch(:hosts_resolver, HostsResolver.new) if RUBY_VERSION >= '2.1' require 'middleman-core/dns_resolver/local_link_resolver' @resolvers << opts.fetch(:local_link_resolver, LocalLinkResolver.new) end @resolvers << opts.fetch(:network_resolver, NetworkResolver.new) end |
Instance Method Details
#ips_for(name) ⇒ Object
Get ips for given name
First the local resolver is used. On POSIX-systems /etc/hosts is used. On Windows C:\Windows\System32\drivers\etc\hosts is used.
63 64 65 66 67 68 69 70 71 |
# File 'lib/middleman-core/dns_resolver.rb', line 63 def ips_for(name) resolvers.each do |r| ips = r.getaddresses(name) return ips unless ips.nil? || ips.empty? end [] end |
#names_for(ip) ⇒ Object
Get names for given ip
46 47 48 49 50 51 52 53 54 |
# File 'lib/middleman-core/dns_resolver.rb', line 46 def names_for(ip) resolvers.each do |r| names = r.getnames(ip) return names unless names.nil? || names.empty? end [] end |