Class: Moped::Operation::Read

Inherits:
Object
  • Object
show all
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.

Since:

  • 2.0.0

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(operation) ⇒ Read

Instantiate the read operation.

Examples:

Instantiate the read.

Read.new(get_more)

Parameters:

Since:

  • 2.0.0



27
28
29
30
# File 'lib/moped/operation/read.rb', line 27

def initialize(operation)
  @operation = operation
  @database = operation.database
end

Instance Attribute Details

#databaseString

Returns The database the read is from.

Returns:

  • (String)

    The database the read is from.



16
17
18
# File 'lib/moped/operation/read.rb', line 16

def database
  @database
end

#operationObject

Since:

  • 2.0.0



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.

Examples:

Execute the operation.

read.execute(node)

Parameters:

  • node (Node)

    The node to execute the read on.

Returns:

Raises:

  • (Failure)

    If the read operation failed.

Since:

  • 2.0.0



47
48
49
50
51
52
53
54
# File 'lib/moped/operation/read.rb', line 47

def execute(node)
  node.process(operation) do |reply|
    if operation.failure?(reply)
      raise operation.failure_exception(reply)
    end
    operation.results(reply)
  end
end