Class: Ashikawa::Core::Cursor
- Inherits:
-
Object
- Object
- Ashikawa::Core::Cursor
- Includes:
- Enumerable
- Defined in:
- lib/ashikawa-core/cursor.rb
Overview
A Cursor on a certain Database. It is an enumerable.
Instance Attribute Summary collapse
-
#id ⇒ String
readonly
The ID of the cursor.
-
#length ⇒ Int
readonly
The number of documents.
Instance Method Summary collapse
-
#delete ⇒ Hash
Delete the cursor.
-
#each {|Object| ... } ⇒ nil, Enumerator
Iterate over the result.
-
#initialize(database, raw_cursor) ⇒ Cursor
constructor
Initialize a Cursor with the database and raw data.
Constructor Details
#initialize(database, raw_cursor) ⇒ Cursor
Initialize a Cursor with the database and raw data
38 39 40 41 |
# File 'lib/ashikawa-core/cursor.rb', line 38 def initialize(database, raw_cursor) @database = database parse_raw_cursor(raw_cursor) end |
Instance Attribute Details
#id ⇒ String (readonly)
The ID of the cursor
21 22 23 |
# File 'lib/ashikawa-core/cursor.rb', line 21 def id @id end |
#length ⇒ Int (readonly)
The number of documents
29 30 31 |
# File 'lib/ashikawa-core/cursor.rb', line 29 def length @length end |
Instance Method Details
#delete ⇒ Hash
Delete the cursor
74 75 76 |
# File 'lib/ashikawa-core/cursor.rb', line 74 def delete @database.send_request("cursor/#{@id}", delete: {}) end |
#each {|Object| ... } ⇒ nil, Enumerator
Iterate over the result
57 58 59 60 61 62 63 64 65 66 |
# File 'lib/ashikawa-core/cursor.rb', line 57 def each return to_enum(__callee__) unless block_given? begin @current.each do |raw_document| yield parse_raw_document(raw_document) end end while next_batch nil end |