Class: Mongo::Protocol::Reply::Upconverter
Relationships & Source Files | |
Inherits: | Object |
Defined in: | lib/mongo/protocol/reply.rb |
Overview
Upconverts legacy replies to new op command replies.
Constant Summary
-
CURSOR =
::Mongo::Cursor
field constant.'cursor'.freeze
-
FIRST_BATCH =
First batch constant.
'firstBatch'.freeze
-
ID =
::Mongo::Id
field constant.'id'.freeze
-
NEXT_BATCH =
Next batch constant.
'nextBatch'.freeze
Class Method Summary
-
.new(documents, cursor_id, starting_from) ⇒ Upconverter
constructor
Initialize the new upconverter.
Instance Attribute Summary
-
#command ⇒ BSON::Document
readonly
Get the upconverted command.
- #cursor_id ⇒ Integer readonly
- #documents ⇒ Array<BSON::Document> readonly
- #starting_from ⇒ Integer readonly
- #command? ⇒ Boolean readonly private
Instance Method Summary
- #batch_field private
- #find_command private
- #op_command private
Constructor Details
.new(documents, cursor_id, starting_from) ⇒ Upconverter
Initialize the new upconverter.
# File 'lib/mongo/protocol/reply.rb', line 152
def initialize(documents, cursor_id, starting_from) @documents = documents @cursor_id = cursor_id @starting_from = starting_from end
Instance Attribute Details
#command ⇒ BSON::Document
(readonly)
Get the upconverted command.
# File 'lib/mongo/protocol/reply.rb', line 175
def command command? ? op_command : find_command end
#command? ⇒ Boolean
(readonly, private)
#cursor_id ⇒ Integer
(readonly)
# File 'lib/mongo/protocol/reply.rb', line 162
attr_reader :cursor_id
#documents ⇒ Array
<BSON::Document
> (readonly)
# File 'lib/mongo/protocol/reply.rb', line 159
attr_reader :documents
#starting_from ⇒ Integer
(readonly)
# File 'lib/mongo/protocol/reply.rb', line 165
attr_reader :starting_from
Instance Method Details
#batch_field (private)
# File 'lib/mongo/protocol/reply.rb', line 181
def batch_field starting_from > 0 ? NEXT_BATCH : FIRST_BATCH end
#find_command (private)
# File 'lib/mongo/protocol/reply.rb', line 189
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 (private)
# File 'lib/mongo/protocol/reply.rb', line 199
def op_command documents.first end