Class: RightSupport::Net::ResolvedEndpoint

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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

#uriObject

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

#addressesObject 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

Returns:

  • (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

#blocksObject



76
77
78
# File 'lib/right_support/net/dns.rb', line 76

def blocks()
  @ip_addresses.map {|addr| addr.to_cidr}
end