Module: CursorPagination::PageScopeMethods
- Defined in:
- lib/cursor_pagination/page_scope_methods.rb
Instance Method Summary collapse
- #first_page? ⇒ Boolean
- #last_page? ⇒ Boolean
- #next_cursor ⇒ Object
- #per(num) ⇒ Object
- #previous_cursor ⇒ Object
Instance Method Details
#first_page? ⇒ Boolean
7 8 9 |
# File 'lib/cursor_pagination/page_scope_methods.rb', line 7 def first_page? previous_cursor == -1 end |
#last_page? ⇒ Boolean
11 12 13 |
# File 'lib/cursor_pagination/page_scope_methods.rb', line 11 def last_page? next_cursor == -1 end |
#next_cursor ⇒ Object
29 30 31 32 33 34 |
# File 'lib/cursor_pagination/page_scope_methods.rb', line 29 def next_cursor return -1 if last.nil? # try to get something after last cursor cursor = last.send([:column]) _origin_scope.cursor(cursor, ).per(1).count.zero? ? -1 : cursor end |
#per(num) ⇒ Object
3 4 5 |
# File 'lib/cursor_pagination/page_scope_methods.rb', line 3 def per(num) limit(num) end |
#previous_cursor ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/cursor_pagination/page_scope_methods.rb', line 15 def previous_cursor = result = _origin_scope.where("#{[:column]} #{[:reverse] ? '>' : '<'}= ?", current_cursor).limit(limit_value+1).to_a case result.size when limit_value+1 result.first.send([:column]) when 0 -1 #no previous page else nil #first page, incomplete end end |