Class: ROM::Solr::SelectCursor
- Inherits:
-
SimpleDelegator
- Object
- SimpleDelegator
- ROM::Solr::SelectCursor
- Defined in:
- lib/rom/solr/select_cursor.rb
Overview
Wraps a DocumentsDataset to provide pagination with a cursor.
Instance Method Summary collapse
- #cursor_mark ⇒ Object
- #each(&block) ⇒ Object
-
#initialize(dataset) ⇒ SelectCursor
constructor
A new instance of SelectCursor.
- #last_page? ⇒ Boolean
- #move_cursor ⇒ Object
- #next_cursor_mark ⇒ Object
- #next_page ⇒ Object
Constructor Details
#initialize(dataset) ⇒ SelectCursor
Returns a new instance of SelectCursor.
10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/rom/solr/select_cursor.rb', line 10 def initialize(dataset) params = { cursorMark: '*' } # Sort must include a sort on unique key (id). sort = dataset.params[:sort] unless /\bid\b/ =~ sort params[:sort] = Array.wrap(sort).append('id ASC').join(',') end super dataset.add_params(params) end |
Instance Method Details
#cursor_mark ⇒ Object
34 35 36 |
# File 'lib/rom/solr/select_cursor.rb', line 34 def cursor_mark params[:cursorMark] end |
#each(&block) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/rom/solr/select_cursor.rb', line 22 def each(&block) return to_enum unless block_given? while true __getobj__.each(&block) break if last_page? move_cursor end end |
#last_page? ⇒ Boolean
42 43 44 |
# File 'lib/rom/solr/select_cursor.rb', line 42 def last_page? cursor_mark == next_cursor_mark end |
#move_cursor ⇒ Object
46 47 48 |
# File 'lib/rom/solr/select_cursor.rb', line 46 def move_cursor __setobj__(next_page) end |
#next_cursor_mark ⇒ Object
38 39 40 |
# File 'lib/rom/solr/select_cursor.rb', line 38 def next_cursor_mark response[:nextCursorMark] end |
#next_page ⇒ Object
50 51 52 |
# File 'lib/rom/solr/select_cursor.rb', line 50 def next_page __getobj__.add_params(cursorMark: next_cursor_mark) end |