Class: Mongo::Address::IPv4
- Inherits:
-
Object
- Object
- Mongo::Address::IPv4
- Defined in:
- lib/mongo/address/ipv4.rb
Overview
Sets up resolution with IPv4 support if the address is an ip address.
Constant Summary collapse
- MATCH =
The regular expression to use to match an IPv4 ip address.
Regexp.new('/\./').freeze
- SPLIT =
Split value constant.
':'.freeze
Instance Attribute Summary collapse
-
#host ⇒ String
readonly
Host The host.
-
#host_name ⇒ String
readonly
Host_name The original host name.
-
#port ⇒ Integer
readonly
Port The port.
Class Method Summary collapse
-
.parse(address) ⇒ Array<String, Integer>
Parse an IPv4 address into its host and port.
Instance Method Summary collapse
-
#initialize(host, port, host_name = nil) ⇒ IPv4
constructor
Initialize the IPv4 resolver.
-
#socket(socket_timeout, options = {}) ⇒ Mongo::Socket::SSL, Mongo::Socket::TCP
private
Get a socket for the provided address type, given the options.
Constructor Details
#initialize(host, port, host_name = nil) ⇒ IPv4
Initialize the IPv4 resolver.
72 73 74 75 76 |
# File 'lib/mongo/address/ipv4.rb', line 72 def initialize(host, port, host_name=nil) @host = host @port = port @host_name = host_name end |
Instance Attribute Details
#host ⇒ String (readonly)
Returns host The host.
28 29 30 |
# File 'lib/mongo/address/ipv4.rb', line 28 def host @host end |
#host_name ⇒ String (readonly)
Returns host_name The original host name.
31 32 33 |
# File 'lib/mongo/address/ipv4.rb', line 31 def host_name @host_name end |
#port ⇒ Integer (readonly)
Returns port The port.
34 35 36 |
# File 'lib/mongo/address/ipv4.rb', line 34 def port @port end |
Class Method Details
.parse(address) ⇒ Array<String, Integer>
Parse an IPv4 address into its host and port.
56 57 58 59 60 61 |
# File 'lib/mongo/address/ipv4.rb', line 56 def self.parse(address) parts = address.split(SPLIT) host = parts[0] port = (parts[1] || 27017).to_i [ host, port ] end |
Instance Method Details
#socket(socket_timeout, options = {}) ⇒ Mongo::Socket::SSL, Mongo::Socket::TCP
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Get a socket for the provided address type, given the options.
119 120 121 122 123 124 125 |
# File 'lib/mongo/address/ipv4.rb', line 119 def socket(socket_timeout, = {}) if [:ssl] Socket::SSL.new(host, port, host_name, socket_timeout, Socket::PF_INET, ) else Socket::TCP.new(host, port, socket_timeout, Socket::PF_INET, ) end end |