Class: Moped::Cursor Private
- Inherits:
-
Object
- Object
- Moped::Cursor
- Includes:
- Enumerable, Readable
- Defined in:
- lib/moped/cursor.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
Contains logic for cursor behaviour.
Instance Attribute Summary collapse
- #get_more_op ⇒ Object readonly private
- #get_more_op The get more message.(Thegetmoremessage.) ⇒ Object readonly
- #kill_cursor_op ⇒ Object readonly private
- #kill_cursor_op The kill cursor message.(Thekillcursormessage.) ⇒ Object readonly
- #query_op ⇒ Object readonly private
- #query_op The query message.(Thequerymessage.) ⇒ Object readonly
- #session ⇒ Object readonly private
- #session The session.(Thesession.) ⇒ Object readonly
Instance Method Summary collapse
-
#each ⇒ Enumerator
private
Iterate over the results of the query.
-
#get_more ⇒ Array<Hash>
private
Get more documents from the database for the cursor.
-
#initialize(session, query_operation) ⇒ Cursor
constructor
private
Initialize the new cursor.
-
#kill ⇒ Object
private
Kill the cursor.
-
#limited? ⇒ true, false
private
Does the cursor have a limit provided in the query?.
-
#load_docs ⇒ Array<Hash>
private
Load the documents from the database.
-
#more? ⇒ true, false
private
Are there more documents to be returned from the database?.
-
#request_limit ⇒ Integer
private
Determine the request limit for the query.
Constructor Details
#initialize(session, query_operation) ⇒ Cursor
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Initialize the new cursor.
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 |
# File 'lib/moped/cursor.rb', line 78 def initialize(session, query_operation) @session = session @database = query_operation.database @collection = query_operation.collection @selector = query_operation.selector @cursor_id = 0 @limit = query_operation.limit @limited = @limit > 0 @batch_size = query_operation.batch_size || @limit @options = { request_id: query_operation.request_id, flags: query_operation.flags, limit: query_operation.limit, skip: query_operation.skip, fields: query_operation.fields, } end |
Instance Attribute Details
#get_more_op ⇒ Object (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
14 15 16 |
# File 'lib/moped/cursor.rb', line 14 def get_more_op @get_more_op end |
#get_more_op The get more message.(Thegetmoremessage.) ⇒ Object (readonly)
14 |
# File 'lib/moped/cursor.rb', line 14 attr_reader :get_more_op, :kill_cursor_op, :query_op, :session |
#kill_cursor_op ⇒ Object (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
14 15 16 |
# File 'lib/moped/cursor.rb', line 14 def kill_cursor_op @kill_cursor_op end |
#kill_cursor_op The kill cursor message.(Thekillcursormessage.) ⇒ Object (readonly)
14 |
# File 'lib/moped/cursor.rb', line 14 attr_reader :get_more_op, :kill_cursor_op, :query_op, :session |
#query_op ⇒ Object (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
14 15 16 |
# File 'lib/moped/cursor.rb', line 14 def query_op @query_op end |
#query_op The query message.(Thequerymessage.) ⇒ Object (readonly)
14 |
# File 'lib/moped/cursor.rb', line 14 attr_reader :get_more_op, :kill_cursor_op, :query_op, :session |
#session ⇒ Object (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
14 15 16 |
# File 'lib/moped/cursor.rb', line 14 def session @session end |
#session The session.(Thesession.) ⇒ Object (readonly)
14 |
# File 'lib/moped/cursor.rb', line 14 attr_reader :get_more_op, :kill_cursor_op, :query_op, :session |
Instance Method Details
#each ⇒ Enumerator
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Iterate over the results of the query.
26 27 28 29 30 31 32 33 34 |
# File 'lib/moped/cursor.rb', line 26 def each documents = load_docs documents.each { |doc| yield doc } while more? return kill if limited? && @limit <= 0 documents = get_more documents.each { |doc| yield doc } end end |
#get_more ⇒ Array<Hash>
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Get more documents from the database for the cursor. Executes a get more command.
45 46 47 48 49 50 |
# File 'lib/moped/cursor.rb', line 45 def get_more reply = @node.get_more @database, @collection, @cursor_id, request_limit @limit -= reply.count if limited? @cursor_id = reply.cursor_id reply.documents end |
#kill ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Kill the cursor.
107 108 109 |
# File 'lib/moped/cursor.rb', line 107 def kill @node.kill_cursors([ @cursor_id ]) end |
#limited? ⇒ true, false
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Does the cursor have a limit provided in the query?
119 120 121 |
# File 'lib/moped/cursor.rb', line 119 def limited? @limited end |
#load_docs ⇒ Array<Hash>
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Load the documents from the database.
131 132 133 134 135 136 137 138 139 140 141 142 143 |
# File 'lib/moped/cursor.rb', line 131 def load_docs @options[:flags] |= [:no_cursor_timeout] if @options[:no_timeout] = @options.clone [:limit] = request_limit reply, @node = read_preference.with_node(session.cluster) do |node| [ node.query(@database, @collection, @selector, ()), node ] end @limit -= reply.count if limited? @cursor_id = reply.cursor_id reply.documents end |
#more? ⇒ true, false
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Are there more documents to be returned from the database?
153 154 155 |
# File 'lib/moped/cursor.rb', line 153 def more? @cursor_id != 0 end |
#request_limit ⇒ Integer
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Determine the request limit for the query
61 62 63 64 65 66 67 |
# File 'lib/moped/cursor.rb', line 61 def request_limit if limited? @batch_size < @limit ? @batch_size : @limit else @batch_size end end |