Class: Middleman::DnsResolver::BasicNetworkResolver

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

Overview

Use network name server to resolve ips and names

Direct Known Subclasses

LocalLinkResolver, NetworkResolver

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}) ⇒ BasicNetworkResolver

Returns a new instance of BasicNetworkResolver.



11
12
13
# File 'lib/middleman-core/dns_resolver/basic_network_resolver.rb', line 11

def initialize(opts={})
  @timeouts = opts.fetch(:timeouts, 2)
end

Instance Attribute Details

#timeouts=(timeouts) ⇒ Object

Set timeout for lookup

Parameters:

  • value (Integer)

    The timeout value



45
46
47
# File 'lib/middleman-core/dns_resolver/basic_network_resolver.rb', line 45

def timeouts=(timeouts)
  resolver.timeouts = timeouts
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



35
36
37
38
39
# File 'lib/middleman-core/dns_resolver/basic_network_resolver.rb', line 35

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

#getnames(ip) ⇒ Array

Get names for ip

Parameters:

  • ip (#to_s)

    The ip to resolve into names

Returns:

  • (Array)

    Array of Names



22
23
24
25
26
# File 'lib/middleman-core/dns_resolver/basic_network_resolver.rb', line 22

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