Class: Moped::Protocol::Command
- Defined in:
- lib/moped/protocol/command.rb
Overview
This is a convenience class on top of Query
for quickly creating a command.
Direct Known Subclasses
Instance Attribute Summary
Attributes inherited from Query
#batch_size, #collection, #database, #fields, #flags, #full_collection_name, #length, #limit, #op_code, #request_id, #selector, #skip
Instance Method Summary collapse
-
#failure?(reply) ⇒ true, false
Determine if the provided reply message is a failure with respect to a command.
-
#failure_exception(reply) ⇒ Moped::Errors::OperationFailure
Get the exception specific to a failure of this particular operation.
-
#initialize(database, command, options = {}) ⇒ Command
constructor
Instantiate the new command.
-
#log_inspect ⇒ String
Provide the value that will be logged when the command runs.
-
#results(reply) ⇒ Hash
Take the provided reply and return the expected results to api consumers.
Methods inherited from Query
#basic_selector, #no_timeout=, #receive_replies
Methods included from Message
included, #inspect, #receive_replies, #serialize
Constructor Details
#initialize(database, command, options = {}) ⇒ Command
Instantiate the new command.
53 54 55 |
# File 'lib/moped/protocol/command.rb', line 53 def initialize(database, command, = {}) super(database, '$cmd', command, .merge(limit: -1)) end |
Instance Method Details
#failure?(reply) ⇒ true, false
Determine if the provided reply message is a failure with respect to a command.
25 26 27 |
# File 'lib/moped/protocol/command.rb', line 25 def failure?(reply) reply.command_failure? end |
#failure_exception(reply) ⇒ Moped::Errors::OperationFailure
Get the exception specific to a failure of this particular operation.
39 40 41 |
# File 'lib/moped/protocol/command.rb', line 39 def failure_exception(reply) Errors::OperationFailure.new(self, reply.documents.first) end |
#log_inspect ⇒ String
Provide the value that will be logged when the command runs.
65 66 67 68 |
# File 'lib/moped/protocol/command.rb', line 65 def log_inspect type = "COMMAND" "%-12s database=%s command=%s" % [type, database, selector.inspect] end |
#results(reply) ⇒ Hash
Take the provided reply and return the expected results to api consumers. In the case of the command it’s the first document.
81 82 83 |
# File 'lib/moped/protocol/command.rb', line 81 def results(reply) reply.documents.first end |