class Mongo::Protocol::Reply::Upconverter

Upconverts legacy replies to new op command replies.

@since 2.1.0

Constants

CURSOR

Cursor field constant.

@since 2.1.0

FIRST_BATCH

First batch constant.

@since 2.1.0

ID

Id field constant.

@since 2.1.0

NEXT_BATCH

Next batch constant.

@since 2.1.0

Attributes

cursor_id[R]

@return [ Integer ] cursor_id The cursor id.

documents[R]

@return [ Array<BSON::Document> ] documents The documents.

starting_from[R]

@return [ Integer ] starting_from The starting point in the cursor.

Public Class Methods

new(documents, cursor_id, starting_from) click to toggle source

Initialize the new upconverter.

@example Create the upconverter.

Upconverter.new(docs, 1, 3)

@param [ Array<BSON::Document> ] documents The documents. @param [ Integer ] cursor_id The cursor id. @param [ Integer ] starting_from The starting position.

@since 2.1.0

# File lib/mongo/protocol/reply.rb, line 149
def initialize(documents, cursor_id, starting_from)
  @documents = documents
  @cursor_id = cursor_id
  @starting_from = starting_from
end

Public Instance Methods

command() click to toggle source

Get the upconverted command.

@example Get the command.

upconverter.command

@return [ BSON::Document ] The command.

@since 2.1.0

# File lib/mongo/protocol/reply.rb, line 172
def command
  command? ? op_command : find_command
end

Private Instance Methods

batch_field() click to toggle source
# File lib/mongo/protocol/reply.rb, line 178
def batch_field
  starting_from > 0 ? NEXT_BATCH : FIRST_BATCH
end
command?() click to toggle source
# File lib/mongo/protocol/reply.rb, line 182
def command?
  !documents.empty? && documents.first.key?(Operation::Result::OK)
end
find_command() click to toggle source
# File lib/mongo/protocol/reply.rb, line 186
def find_command
  document = BSON::Document.new
  cursor_document = BSON::Document.new
  cursor_document.store(ID, cursor_id)
  cursor_document.store(batch_field, documents)
  document.store(Operation::Result::OK, 1)
  document.store(CURSOR, cursor_document)
  document
end
op_command() click to toggle source
# File lib/mongo/protocol/reply.rb, line 196
def op_command
  documents.first
end