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.
-
#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(timeout, ssl_options = {}) ⇒ Pool::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 |
# File 'lib/mongo/address.rb', line 119 def initialize(seed, = {}) @seed = seed @host, @port = parse_host_port 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 |
#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.
132 133 134 |
# File 'lib/mongo/address.rb', line 132 def inspect "#<Mongo::Address:0x#{object_id} address=#{to_s}>" end |
#socket(timeout, ssl_options = {}) ⇒ Pool::Socket::SSL, ...
Get a socket for the provided address, given the options.
147 148 149 150 |
# File 'lib/mongo/address.rb', line 147 def socket(timeout, = {}) @resolver ||= initialize_resolver!(timeout, ) @resolver.socket(timeout, ) end |
#to_s ⇒ String
Get the address as a string.
160 161 162 |
# File 'lib/mongo/address.rb', line 160 def to_s port ? "#{host}:#{port}" : host end |