module Mongo::Operation::Executable

This module provides the execute method that many operations use. It makes sure to instantiate the appropriate Result class for the operation's response.

@since 2.0.0

Public Instance Methods

execute(context) click to toggle source

Execute the operation. The context gets a connection on which the operation is sent in the block.

@param [ Mongo::Server::Context ] context The context for this operation.

@return [ Result ] The operation response, if there is one.

@since 2.0.0

# File lib/mongo/operation/executable.rb, line 33
def execute(context)
  context.with_connection do |connection|
    result_class = self.class.const_defined?(:Result, false) ? self.class::Result : Result
    result_class.new(connection.dispatch([ message(context) ], operation_id)).validate!
  end
end