Class: Moped::Protocol::Reply
- Inherits:
-
Object
- Object
- Moped::Protocol::Reply
- Includes:
- Message
- Defined in:
- lib/moped/protocol/reply.rb
Overview
The Protocol class representing messages received from a mongo connection.
Constant Summary collapse
- UNAUTHORIZED =
Unauthorized assertion errors.
[ 10057, 16550 ]
Instance Attribute Summary collapse
-
#count ⇒ Number
The number of documents returned.
-
#cursor_id ⇒ Number
The id of the cursor on the server.
-
#documents ⇒ Array
The returned documents.
-
#flags ⇒ Array<Symbol>
The flags for this reply.
-
#length ⇒ Number
The length of the message.
-
#offset ⇒ Number
The starting position within the cursor.
-
#op_code ⇒ Number
The operation code of this message (always 1).
-
#request_id ⇒ Number
The request id of the message.
-
#response_to ⇒ Number
The id that generated the message.
Class Method Summary collapse
-
.deserialize(buffer) ⇒ Reply
Consumes a buffer, returning the deserialized Reply message.
Instance Method Summary collapse
-
#command_failure? ⇒ true, false
Is the reply the result of a command failure?.
-
#cursor_not_found? ⇒ true, false
Was the provided cursor id not found on the server?.
-
#error? ⇒ true, false
Check if the first returned document in the reply is an error result.
-
#query_failure? ⇒ true, false
Did the query fail on the server?.
-
#unauthorized? ⇒ true, false
Is the reply an error message that we are not authorized for the query or command?.
Methods included from Message
included, #inspect, #receive_replies, #serialize
Instance Attribute Details
#count ⇒ Number
51 |
# File 'lib/moped/protocol/reply.rb', line 51 int32 :count |
#cursor_id ⇒ Number
43 |
# File 'lib/moped/protocol/reply.rb', line 43 int64 :cursor_id |
#documents ⇒ Array
55 |
# File 'lib/moped/protocol/reply.rb', line 55 document :documents, type: :array |
#flags ⇒ Array<Symbol>
37 38 39 |
# File 'lib/moped/protocol/reply.rb', line 37 flags :flags, cursor_not_found: 2 ** 0, query_failure: 2 ** 1, await_capable: 2 ** 3 |
#length ⇒ Number
21 |
# File 'lib/moped/protocol/reply.rb', line 21 int32 :length |
#offset ⇒ Number
47 |
# File 'lib/moped/protocol/reply.rb', line 47 int32 :offset |
#op_code ⇒ Number
33 |
# File 'lib/moped/protocol/reply.rb', line 33 int32 :op_code |
#request_id ⇒ Number
25 |
# File 'lib/moped/protocol/reply.rb', line 25 int32 :request_id |
#response_to ⇒ Number
29 |
# File 'lib/moped/protocol/reply.rb', line 29 int32 :response_to |
Class Method Details
.deserialize(buffer) ⇒ Reply
Consumes a buffer, returning the deserialized Reply message.
reply from.
145 146 147 148 149 150 151 |
# File 'lib/moped/protocol/reply.rb', line 145 def deserialize(buffer) reply = allocate fields.each do |field| reply.__send__ :"deserialize_#{field}", buffer end reply end |
Instance Method Details
#command_failure? ⇒ true, false
This is when ok is not 1, or “err” or “errmsg” are present.
Is the reply the result of a command failure?
69 70 71 72 |
# File 'lib/moped/protocol/reply.rb', line 69 def command_failure? result = documents.first (result["ok"] != 1.0 && result["ok"] != true) || error? end |
#cursor_not_found? ⇒ true, false
Was the provided cursor id not found on the server?
82 83 84 |
# File 'lib/moped/protocol/reply.rb', line 82 def cursor_not_found? flags.include?(:cursor_not_found) end |
#error? ⇒ true, false
Check if the first returned document in the reply is an error result.
94 95 96 97 |
# File 'lib/moped/protocol/reply.rb', line 94 def error? result = documents.first result && (result) end |
#query_failure? ⇒ true, false
Did the query fail on the server?
107 108 109 |
# File 'lib/moped/protocol/reply.rb', line 107 def query_failure? flags.include?(:query_failure) || error? end |
#unauthorized? ⇒ true, false
So far this can be a “code” of 10057 in the error message or an “assertionCode” of 10057.
Is the reply an error message that we are not authorized for the query or command?
123 124 125 126 127 128 129 130 |
# File 'lib/moped/protocol/reply.rb', line 123 def result = documents[0] return false if result.nil? err = (result) UNAUTHORIZED.include?(result["code"]) || UNAUTHORIZED.include?(result["assertionCode"]) || (err && (err =~ /unauthorized/ || err =~ /not authorized/)) end |