Class: Tina4::DocStore::Cursor
- Inherits:
-
Object
- Object
- Tina4::DocStore::Cursor
- Includes:
- Enumerable
- Defined in:
- lib/tina4/docstore.rb
Overview
Lazy result cursor. Builds and runs SQL only when iterated.
Instance Method Summary collapse
- #each ⇒ Object
-
#initialize(conn, quoted_name, where, params, projection = nil) ⇒ Cursor
constructor
The cursor receives WHAT IT NEEDS, not the collection it came from.
- #limit(num) ⇒ Object
- #skip(num) ⇒ Object
- #sort(key_or_list, direction = 1) ⇒ Object
- #to_a ⇒ Object
-
#to_list ⇒ Object
The uniform Tina4 spelling, ADDITIVE to to_a (ADR-0035).
Constructor Details
#initialize(conn, quoted_name, where, params, projection = nil) ⇒ Cursor
The cursor receives WHAT IT NEEDS, not the collection it came from.
It used to hold the collection and reach back into it for quoted_name, connection and load_doc - which was the ONLY reason those three were public. ADR-0025 corollary 1: anything the fallback needs internally is private, and a real Mongo::Collection::View exposes none of them.
482 483 484 485 486 487 488 489 490 491 |
# File 'lib/tina4/docstore.rb', line 482 def initialize(conn, quoted_name, where, params, projection = nil) @conn = conn @quoted_name = quoted_name @where = where @params = params @projection = projection @sort = [] @limit = nil @skip = 0 end |
Instance Method Details
#each ⇒ Object
523 524 525 526 527 528 529 530 |
# File 'lib/tina4/docstore.rb', line 523 def each return enum_for(:each) unless block_given? @conn.execute(build_sql, @params).each do |row| doc_text = row.is_a?(Hash) ? (row["doc"] || row[:doc] || row.values.first) : row.first yield DocStore.load_doc(doc_text, @projection) end end |
#limit(num) ⇒ Object
498 499 500 501 |
# File 'lib/tina4/docstore.rb', line 498 def limit(num) @limit = num.to_i self end |
#skip(num) ⇒ Object
503 504 505 506 |
# File 'lib/tina4/docstore.rb', line 503 def skip(num) @skip = num.to_i self end |
#sort(key_or_list, direction = 1) ⇒ Object
493 494 495 496 |
# File 'lib/tina4/docstore.rb', line 493 def sort(key_or_list, direction = 1) @sort.concat(DocStore.sort_spec(key_or_list, direction)) self end |
#to_a ⇒ Object
532 533 534 535 536 |
# File 'lib/tina4/docstore.rb', line 532 def to_a out = [] each { |doc| out << doc } out end |
#to_list ⇒ Object
The uniform Tina4 spelling, ADDITIVE to to_a (ADR-0035).
ADR-0025 corollary 1 removed this because Mongo::Collection::View has no to_list. ADR-0035 amends that corollary: a method may exist here when it also exists on WHAT get_collection RETURNS for the real provider, and MongoView supplies it there. to_a stays - it is the driver's spelling and the Ruby idiom - so both work on both providers.
545 |
# File 'lib/tina4/docstore.rb', line 545 def to_list = to_a |