Class: Mongo::Address::Unix

Inherits:
Object
  • Object
show all
Defined in:
lib/mongo/address/unix.rb

Overview

Sets up socket addresses.

Since:

  • 2.0.0

Constant Summary

MATCH =

The regular expression to use to match a socket path.

Since:

  • 2.0.0

Regexp.new('\.sock').freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(host, port = nil, host_name = nil) ⇒ Unix

Initialize the socket resolver.

Examples:

Initialize the resolver.

Unix.new("/path/to/socket.sock", "/path/to/socket.sock")

Parameters:

  • host (String)

    The host.

Since:

  • 2.0.0



56
57
58
# File 'lib/mongo/address/unix.rb', line 56

def initialize(host, port=nil, host_name=nil)
  @host = host
end

Instance Attribute Details

#hostString (readonly)

Returns host The host.

Returns:

  • (String)

    host The host.

Since:

  • 2.0.0



24
25
26
# File 'lib/mongo/address/unix.rb', line 24

def host
  @host
end

#portnil (readonly)

Returns port Will always be nil.

Returns:

  • (nil)

    port Will always be nil.

Since:

  • 2.0.0



27
28
29
# File 'lib/mongo/address/unix.rb', line 27

def port
  @port
end

Class Method Details

.parse(address) ⇒ Array<String>

Parse a socket path.

Examples:

Parse the address.

Unix.parse("/path/to/socket.sock")

Parameters:

  • address (String)

    The address to parse.

Returns:

  • (Array<String>)

    A list with the host (socket path).

Since:

  • 2.0.0



44
45
46
# File 'lib/mongo/address/unix.rb', line 44

def self.parse(address)
  [ address ]
end

Instance Method Details

#socket(socket_timeout, ssl_options = {}) ⇒ Pool::Socket::Unix

Get a socket for the provided address type, given the options.

Examples:

Get a Unix socket.

address.socket(5)

Parameters:

  • timeout (Float)

    The socket timeout.

  • ssl_options (Hash) (defaults to: {})

    SSL options - ignored.

Returns:

  • (Pool::Socket::Unix)

    The socket.

Since:

  • 2.0.0



71
72
73
# File 'lib/mongo/address/unix.rb', line 71

def socket(socket_timeout, ssl_options = {})
  Socket::Unix.new(host, socket_timeout)
end