Class: RightSupport::Net::ResolvedEndpoint
- Defined in:
- lib/right_support/net/dns.rb
Overview
A ResolvedEndpoint represents the resolution of a host which can contain multiple IP addresses or entire IP address ranges of varying size.
Instance Attribute Summary collapse
-
#uri ⇒ Object
Returns the value of attribute uri.
Instance Method Summary collapse
- #==(another_endpoint) ⇒ Object
- #addresses ⇒ Object (also: #addrs)
- #all_hosts? ⇒ Boolean
- #blocks ⇒ Object
-
#initialize(ips, opts = {}) ⇒ ResolvedEndpoint
constructor
A new instance of ResolvedEndpoint.
Constructor Details
#initialize(ips, opts = {}) ⇒ ResolvedEndpoint
Returns a new instance of ResolvedEndpoint.
50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/right_support/net/dns.rb', line 50 def initialize(ips, opts={}) @ip_addresses = [] @uri = opts[:uri] ips.to_a.each do |address| @ip_addresses << IPNet.new(address) end unless self.all_hosts? || @uri == nil raise URI::InvalidURIError, "Cannot resolve URI with CIDR block bigger than a single host" unless self.all_hosts? end end |
Instance Attribute Details
#uri ⇒ Object
Returns the value of attribute uri.
48 49 50 |
# File 'lib/right_support/net/dns.rb', line 48 def uri @uri end |
Instance Method Details
#==(another_endpoint) ⇒ Object
84 85 86 |
# File 'lib/right_support/net/dns.rb', line 84 def ==(another_endpoint) another_endpoint.addresses.all? {|addr| addresses.member? addr } && another_endpoint.uri == @uri end |
#addresses ⇒ Object Also known as: addrs
63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/right_support/net/dns.rb', line 63 def addresses() @ip_addresses.map do |addr| if addr.to_range.count == 1 && @uri != nil transformed_uri = uri.dup transformed_uri.host = addr.to_s transformed_uri.to_s else addr end end end |
#all_hosts? ⇒ Boolean
80 81 82 |
# File 'lib/right_support/net/dns.rb', line 80 def all_hosts?() @ip_addresses.all? {|addr| addr.to_range.count == 1} end |
#blocks ⇒ Object
76 77 78 |
# File 'lib/right_support/net/dns.rb', line 76 def blocks() @ip_addresses.map {|addr| addr.to_cidr} end |