Class: Mongo::Server::Context

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/mongo/server/context.rb

Overview

Represents a context in which messages are sent to the server on a connection.

Since:

  • 2.0.0

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(server) ⇒ Context

Instantiate a server context.

Examples:

Instantiate a server context.

Mongo::Server::Context.new(server)

Parameters:

Since:

  • 2.0.0



47
48
49
# File 'lib/mongo/server/context.rb', line 47

def initialize(server)
  @server = server
end

Instance Attribute Details

#serverMongo::Server (readonly)

Returns server The server the context is for.

Returns:

Since:

  • 2.0.0



26
27
28
# File 'lib/mongo/server/context.rb', line 26

def server
  @server
end

Instance Method Details

#with_connection(&block) ⇒ Object

Execute a block of code with a connection, that is checked out of the pool and then checked back in.

Examples:

Send a message with the connection.

context.with_connection do |connection|
  connection.dispatch([ command ])
end

Returns:

  • (Object)

    The result of the block execution.

Since:

  • 2.0.0



62
63
64
# File 'lib/mongo/server/context.rb', line 62

def with_connection(&block)
  server.pool.with_connection(&block)
end