Class: Mongo::Address::IPv6
Relationships & Source Files | |
Inherits: | Object |
Defined in: | lib/mongo/address/ipv6.rb |
Overview
Sets up resolution with IPv6
support if the address is an ip address.
Constant Summary
-
MATCH =
The regular expression to use to match an
IPv6
ip address.Regexp.new('::').freeze
Class Method Summary
-
.new(host, port, host_name = nil) ⇒ IPv6
constructor
Initialize the
IPv6
resolver. -
.parse(address) ⇒ Array<String, Integer>
Parse an
IPv6
address into its host and port.
Instance Attribute Summary
- #host ⇒ String readonly
- #host_name ⇒ String readonly
- #port ⇒ Integer readonly
Instance Method Summary
-
#socket(socket_timeout, options = {}) ⇒ Mongo::Socket::SSL, Mongo::Socket::TCP
Internal use only
Internal use only
Get a socket for the provided address type, given the options.
Constructor Details
.new(host, port, host_name = nil) ⇒ IPv6
Initialize the IPv6
resolver.
Class Method Details
.parse(address) ⇒ Array
<String
, Integer
>
Parse an IPv6
address into its host and port.
# File 'lib/mongo/address/ipv6.rb', line 51
def self.parse(address) # IPAddr's parser handles IP address only, not port. # Therefore we need to handle the port ourselves if address =~ /[\[\]]/ parts = address.match(/\A\[(.+)\](?::(\d+))?\z/) if parts.nil? raise ArgumentError, "Invalid IPv6 address: #{address}" end host = parts[1] port = (parts[2] || 27017).to_i else host = address port = 27017 end # Validate host. # This will raise IPAddr::InvalidAddressError # on newer rubies which is a subclass of ArgumentError # if host is invalid begin IPAddr.new(host) rescue ArgumentError raise ArgumentError, "Invalid IPv6 address: #{address}" end [ host, port ] end
Instance Attribute Details
#host ⇒ String
(readonly)
# File 'lib/mongo/address/ipv6.rb', line 28
attr_reader :host
#host_name ⇒ String
(readonly)
# File 'lib/mongo/address/ipv6.rb', line 31
attr_reader :host_name
#port ⇒ Integer
(readonly)
# File 'lib/mongo/address/ipv6.rb', line 34
attr_reader :port
Instance Method Details
#socket(socket_timeout, options = {}) ⇒ Mongo::Socket::SSL, Mongo::Socket::TCP
This method is for internal use only.
Get a socket for the provided address type, given the options.