Class: Mongo::Address
- Inherits:
-
Object
- Object
- Mongo::Address
- Extended by:
- Forwardable
- Defined in:
- lib/mongo/address.rb,
lib/mongo/address/ipv4.rb,
lib/mongo/address/ipv6.rb,
lib/mongo/address/unix.rb
Overview
Represents an address to a server, either with an IP address or socket path.
Defined Under Namespace
Constant Summary collapse
- FAMILY_MAP =
Mapping from socket family to resolver class.
{ ::Socket::PF_UNIX => Unix, ::Socket::AF_INET6 => IPv6, ::Socket::AF_INET => IPv4 }.freeze
- LOCALHOST =
The localhost constant.
'localhost'.freeze
Instance Attribute Summary collapse
-
#host ⇒ String
readonly
Host The original host name.
-
#port ⇒ Integer
readonly
Port The port.
-
#seed ⇒ String
readonly
Seed The seed address.
Instance Method Summary collapse
-
#==(other) ⇒ true, false
Check equality of the address to another.
-
#connect_socket!(socket) ⇒ Object
Connect a socket.
-
#eql?(other) ⇒ true, false
Check equality for hashing.
-
#hash ⇒ Integer
Calculate the hash value for the address.
-
#initialize(seed, options = {}) ⇒ Address
constructor
Initialize the address.
-
#inspect ⇒ String
Get a pretty printed address inspection.
-
#socket(socket_timeout, ssl_options = {}) ⇒ Mongo::Socket::SSL, ...
Get a socket for the provided address, given the options.
-
#to_s ⇒ String
Get the address as a string.
Constructor Details
#initialize(seed, options = {}) ⇒ Address
Initialize the address.
119 120 121 122 123 |
# File 'lib/mongo/address.rb', line 119 def initialize(seed, = {}) @seed = seed @host, @port = parse_host_port @options = end |
Instance Attribute Details
#host ⇒ String (readonly)
Returns host The original host name.
46 47 48 |
# File 'lib/mongo/address.rb', line 46 def host @host end |
#port ⇒ Integer (readonly)
Returns port The port.
49 50 51 |
# File 'lib/mongo/address.rb', line 49 def port @port end |
#seed ⇒ String (readonly)
Returns seed The seed address.
43 44 45 |
# File 'lib/mongo/address.rb', line 43 def seed @seed end |
Instance Method Details
#==(other) ⇒ true, false
Check equality of the address to another.
61 62 63 64 |
# File 'lib/mongo/address.rb', line 61 def ==(other) return false unless other.is_a?(Address) host == other.host && port == other.port end |
#connect_socket!(socket) ⇒ Object
Connect a socket.
179 180 181 |
# File 'lib/mongo/address.rb', line 179 def connect_socket!(socket) socket.connect!(connect_timeout) end |
#eql?(other) ⇒ true, false
Check equality for hashing.
76 77 78 |
# File 'lib/mongo/address.rb', line 76 def eql?(other) self == other end |
#hash ⇒ Integer
Calculate the hash value for the address.
88 89 90 |
# File 'lib/mongo/address.rb', line 88 def hash [ host, port ].hash end |
#inspect ⇒ String
Get a pretty printed address inspection.
133 134 135 |
# File 'lib/mongo/address.rb', line 133 def inspect "#<Mongo::Address:0x#{object_id} address=#{to_s}>" end |
#socket(socket_timeout, ssl_options = {}) ⇒ Mongo::Socket::SSL, ...
Get a socket for the provided address, given the options.
148 149 150 151 |
# File 'lib/mongo/address.rb', line 148 def socket(socket_timeout, = {}) @resolver ||= initialize_resolver!() @resolver.socket(socket_timeout, ) end |
#to_s ⇒ String
Get the address as a string.
161 162 163 164 165 166 167 168 169 170 171 |
# File 'lib/mongo/address.rb', line 161 def to_s if port if host.include?(':') "[#{host}]:#{port}" else "#{host}:#{port}" end else host end end |