class Resolv::Hosts

Parent:
Object

Resolv::Hosts is a hostname resolver that uses the system hosts file.

Constants

DefaultFileName

Public Class Methods

new(filename = DefaultFileName) Show source
# File lib/resolv.rb, line 180
def initialize(filename = DefaultFileName)
  @filename = filename
  @mutex = Thread::Mutex.new
  @initialized = nil
end

Creates a new Resolv::Hosts, using filename for its data source.

Public Instance Methods

each_address(name, &proc) Show source
# File lib/resolv.rb, line 237
def each_address(name, &proc)
  lazy_initialize
  if @name2addr.include?(name)
    @name2addr[name].each(&proc)
  end
end

Iterates over all IP addresses for name retrieved from the hosts file.

each_name(address, &proc) Show source
# File lib/resolv.rb, line 264
def each_name(address, &proc)
  lazy_initialize
  @addr2name[address]&.each(&proc)
end

Iterates over all hostnames for address retrieved from the hosts file.

getaddress(name) Show source
# File lib/resolv.rb, line 220
def getaddress(name)
  each_address(name) {|address| return address}
  raise ResolvError.new("#{@filename} has no name: #{name}")
end

Gets the IP address of name from the hosts file.

getaddresses(name) Show source
# File lib/resolv.rb, line 228
def getaddresses(name)
  ret = []
  each_address(name) {|address| ret << address}
  return ret
end

Gets all IP addresses for name from the hosts file.

getname(address) Show source
# File lib/resolv.rb, line 247
def getname(address)
  each_name(address) {|name| return name}
  raise ResolvError.new("#{@filename} has no address: #{address}")
end

Gets the hostname of address from the hosts file.

getnames(address) Show source
# File lib/resolv.rb, line 255
def getnames(address)
  ret = []
  each_name(address) {|name| ret << name}
  return ret
end

Gets all hostnames for address from the hosts file.

Ruby Core © 1993–2017 Yukihiro Matsumoto
Licensed under the Ruby License.
Ruby Standard Library © contributors
Licensed under their own licenses.