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 collapse

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



59
60
61
# File 'lib/mongo/address/unix.rb', line 59

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



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

def host
  @host
end

#portnil (readonly)

Returns port Will always be nil.

Returns:

  • (nil)

    port Will always be nil.

Since:

  • 2.0.0



30
31
32
# File 'lib/mongo/address/unix.rb', line 30

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



47
48
49
# File 'lib/mongo/address/unix.rb', line 47

def self.parse(address)
  [ address ]
end

Instance Method Details

#socket(socket_timeout, options = {}) ⇒ Mongo::Socket::Unix

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.

Examples:

Get a Unix socket.

address.socket(5)

Parameters:

  • socket_timeout (Float)

    The socket timeout.

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

    The options.

Options Hash (options):

  • :connect_timeout (Float)

    Connect timeout.

Returns:

Since:

  • 2.0.0



77
78
79
# File 'lib/mongo/address/unix.rb', line 77

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