Class: Bifrossht::Target

Inherits:
Object
  • Object
show all
Defined in:
lib/bifrossht/target.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(host, port) ⇒ Target

Returns a new instance of Target.


9
10
11
12
# File 'lib/bifrossht/target.rb', line 9

def initialize(host, port)
  @entries = [host]
  @port = port.to_i
end

Instance Attribute Details

#entriesObject (readonly)

Returns the value of attribute entries


6
7
8
# File 'lib/bifrossht/target.rb', line 6

def entries
  @entries
end

#portObject (readonly)

Returns the value of attribute port


7
8
9
# File 'lib/bifrossht/target.rb', line 7

def port
  @port
end

Instance Method Details

#hostObject


24
25
26
# File 'lib/bifrossht/target.rb', line 24

def host
  @entries.last
end

#ipObject


32
33
34
35
36
# File 'lib/bifrossht/target.rb', line 32

def ip
  @ip ||= IPAddr.new host
rescue IPAddr::InvalidAddressError
  nil
end

#ip?Boolean

Returns:

  • (Boolean)

38
39
40
# File 'lib/bifrossht/target.rb', line 38

def ip?
  !ip.nil?
end

#orig_hostObject


20
21
22
# File 'lib/bifrossht/target.rb', line 20

def orig_host
  @entries.first
end

#resolvable?Boolean

Returns:

  • (Boolean)

46
47
48
# File 'lib/bifrossht/target.rb', line 46

def resolvable?
  !resolved_ip.nil?
end

#resolved_ipObject


42
43
44
# File 'lib/bifrossht/target.rb', line 42

def resolved_ip
  @resolved_ip ||= resolve_address
end

#rewrite(new) ⇒ Object


14
15
16
17
18
# File 'lib/bifrossht/target.rb', line 14

def rewrite(new)
  return if new == host

  @entries.push(new)
end

#to_sObject


28
29
30
# File 'lib/bifrossht/target.rb', line 28

def to_s
  host
end