Parent

Included Modules

Class/Module Index [+]

Quicksearch

Moped::Protocol::Reply

The Protocol class representing messages received from a mongo connection.

@example

socket = TCPSocket.new "127.0.0.1", 27017
command = Moped::Protocol::Command.new "admin", buildinfo: 1
socket.write command.serialize
reply = Moped::Protocol::Reply.deserialize(socket)
reply.documents[0]["version"] # => "2.0.0"

Constants

UNAUTHORIZED

Public Class Methods

deserialize(buffer) click to toggle source

Consumes a buffer, returning the deserialized Reply message.

@example

socket = TCPSocket.new "localhost", 27017
socket.write Moped::Protocol::Command.new(:admin, ismaster: 1).serialize
reply = Moped::Protocol::Reply.deserialize(socket)
reply.documents[0]['ismaster'] # => 1

@param [read] buffer an IO or IO-like resource to deserialize the reply from. @return [Reply] the deserialized reply

# File lib/moped/protocol/reply.rb, line 127
def deserialize(buffer)
  reply = allocate
  fields.each do |field|
    reply.__send__ :"deserialize_#{field}", buffer
  end
  reply
end

Public Instance Methods

command_failure?() click to toggle source

Is the reply the result of a command failure?

@example Did the command fail?

reply.command_failure?

@note This is when ok is not 1, or "err" or "errmsg" are present.

@return [ true, false ] If the command failed.

@since 1.2.10

# File lib/moped/protocol/reply.rb, line 68
def command_failure?
  result = documents[0]
  result["ok"] != 1 || result["err"] || result["errmsg"]
end
cursor_not_found?() click to toggle source

Was the provided cursor id not found on the server?

@example Is the cursor not on the server?

reply.cursor_not_found?

@return [ true, false ] If the cursor went missing.

@since 1.2.0

# File lib/moped/protocol/reply.rb, line 81
def cursor_not_found?
  flags.include?(:cursor_not_found)
end
query_failed?() click to toggle source

Did the query fail on the server?

@example Did the query fail?

reply.query_failed?

@return [ true, false ] If the query failed.

@since 1.2.0

# File lib/moped/protocol/reply.rb, line 93
def query_failed?
  flags.include?(:query_failure)
end
unauthorized?() click to toggle source

Is the reply an error message that we are not authorized for the query or command?

@example Was the query unauthorized.

reply.unauthorized?

@note So far this can be a "code" of 10057 in the error message or an

"assertionCode" of 10057.

@return [ true, false ] If we had an authorization error.

@since 1.2.10

# File lib/moped/protocol/reply.rb, line 109
def unauthorized?
  result = documents[0]
  result["code"] == UNAUTHORIZED || result["assertionCode"] == UNAUTHORIZED
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.