Class: DNS::ResolveHost::Substitute::ResolveHost

Inherits:
Object
  • Object
show all
Defined in:
lib/dns/resolve_host/substitute.rb

Instance Method Summary collapse

Instance Method Details

#call(hostname) ⇒ Object



9
10
11
12
13
14
15
16
17
# File 'lib/dns/resolve_host/substitute.rb', line 9

def call(hostname)
  if map.key? hostname
    map[hostname]
  elsif ip_address? hostname
    [hostname]
  else
    raise ResolutionError
  end
end

#ip_address?(string) ⇒ Boolean

Returns:

  • (Boolean)


19
20
21
22
23
24
# File 'lib/dns/resolve_host/substitute.rb', line 19

def ip_address?(string)
  IPAddr.new string
  true
rescue IPAddr::InvalidAddressError
  false
end

#mapObject



34
35
36
# File 'lib/dns/resolve_host/substitute.rb', line 34

def map
  @map ||= {}
end

#set(hostname, ip_addresses) ⇒ Object



26
27
28
29
30
31
32
# File 'lib/dns/resolve_host/substitute.rb', line 26

def set(hostname, ip_addresses)
  ip_addresses = Array(ip_addresses)

  map[hostname] = ip_addresses

  ip_addresses
end