Class: Moped::Operation::Read
- Inherits:
-
Object
- Object
- Moped::Operation::Read
- Defined in:
- lib/moped/operation/read.rb
Overview
Represents a read from the database that is executed on a specific node determined by a read preference.
Instance Attribute Summary collapse
-
#database ⇒ String
The database the read is from.
- #operation ⇒ Object
Instance Method Summary collapse
-
#execute(node) ⇒ Protocol::Reply
Execute the read operation on the provided node.
-
#initialize(operation) ⇒ Read
constructor
Instantiate the read operation.
Constructor Details
#initialize(operation) ⇒ Read
Instantiate the read operation.
27 28 29 30 |
# File 'lib/moped/operation/read.rb', line 27 def initialize(operation) @operation = operation @database = operation.database end |
Instance Attribute Details
#database ⇒ String
Returns The database the read is from.
16 17 18 |
# File 'lib/moped/operation/read.rb', line 16 def database @database end |
#operation ⇒ Object
16 |
# File 'lib/moped/operation/read.rb', line 16 attr_reader :database, :operation |
Instance Method Details
#execute(node) ⇒ Protocol::Reply
Execute the read operation on the provided node. If the query failed, we will check if the failure was due to authorization and attempt the operation again. This could sometimes happen in the case of a step down or reconfiguration on the server side.
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/moped/operation/read.rb', line 47 def execute(node) node.process(operation) do |reply| # Avoid LocalJumpError ret = nil if reply. && node.credentials.key?(@database) node.connection do |conn| username, password = node.credentials[@database] if username && password conn.login(operation.database, username, password) ret = execute(node) end end end if ret.nil? if operation.failure?(reply) raise operation.failure_exception(reply) end ret = operation.results(reply) end ret end end |