Class: Bifrossht::Target
- Inherits:
-
Object
- Object
- Bifrossht::Target
- Defined in:
- lib/bifrossht/target.rb
Instance Attribute Summary collapse
-
#entries ⇒ Object
readonly
Returns the value of attribute entries.
-
#port ⇒ Object
readonly
Returns the value of attribute port.
Instance Method Summary collapse
- #host ⇒ Object
-
#initialize(host, port) ⇒ Target
constructor
A new instance of Target.
- #ip ⇒ Object
- #ip? ⇒ Boolean
- #orig_host ⇒ Object
- #resolvable? ⇒ Boolean
- #resolved_ip ⇒ Object
- #rewrite(new) ⇒ Object
- #to_s ⇒ Object
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
#entries ⇒ Object (readonly)
Returns the value of attribute entries.
6 7 8 |
# File 'lib/bifrossht/target.rb', line 6 def entries @entries end |
#port ⇒ Object (readonly)
Returns the value of attribute port.
7 8 9 |
# File 'lib/bifrossht/target.rb', line 7 def port @port end |
Instance Method Details
#host ⇒ Object
24 25 26 |
# File 'lib/bifrossht/target.rb', line 24 def host @entries.last end |
#ip ⇒ Object
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
38 39 40 |
# File 'lib/bifrossht/target.rb', line 38 def ip? !ip.nil? end |
#orig_host ⇒ Object
20 21 22 |
# File 'lib/bifrossht/target.rb', line 20 def orig_host @entries.first end |
#resolvable? ⇒ Boolean
46 47 48 |
# File 'lib/bifrossht/target.rb', line 46 def resolvable? !resolved_ip.nil? end |
#resolved_ip ⇒ Object
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_s ⇒ Object
28 29 30 |
# File 'lib/bifrossht/target.rb', line 28 def to_s host end |