Class: Cursed::Collection
- Inherits:
-
Object
- Object
- Cursed::Collection
- Extended by:
- Forwardable
- Includes:
- Enumerable
- Defined in:
- lib/cursed/collection.rb
Instance Method Summary collapse
-
#current_page ⇒ Page
The current page.
-
#initialize(relation:, cursor:, adapter: nil) ⇒ Collection
constructor
A new instance of Collection.
-
#invalidate! ⇒ Object
invalidates the #current_page, #next_page and #prev_page.
-
#next_page ⇒ Page
The page following this one.
-
#next_page? ⇒ Boolean
True if there are records that follow records in the current page.
-
#prev_page ⇒ Page
The page previous to this one.
-
#prev_page? ⇒ Boolean
True if there are records that preceede records in the current page.
Constructor Details
#initialize(relation:, cursor:, adapter: nil) ⇒ Collection
Returns a new instance of Collection.
17 18 19 20 21 |
# File 'lib/cursed/collection.rb', line 17 def initialize(relation:, cursor:, adapter: nil) @relation = relation @cursor = cursor @adapter = Cursed::Adapter(adapter || relation) end |
Instance Method Details
#current_page ⇒ Page
Returns the current page.
30 31 32 |
# File 'lib/cursed/collection.rb', line 30 def current_page @current_page ||= build_page(cursor) end |
#invalidate! ⇒ Object
invalidates the #current_page, #next_page and #prev_page
25 26 27 |
# File 'lib/cursed/collection.rb', line 25 def invalidate! [prev_page, next_page, current_page].each(&:invalidate!) end |
#next_page ⇒ Page
Returns the page following this one.
35 36 37 |
# File 'lib/cursed/collection.rb', line 35 def next_page @next_page ||= build_page(current_page.next_page_cursor) end |
#next_page? ⇒ Boolean
Returns true if there are records that follow records in the current page.
45 46 47 |
# File 'lib/cursed/collection.rb', line 45 def next_page? next_page.any? end |
#prev_page ⇒ Page
Returns the page previous to this one.
40 41 42 |
# File 'lib/cursed/collection.rb', line 40 def prev_page @prev_page ||= build_page(current_page.prev_page_cursor) end |
#prev_page? ⇒ Boolean
Returns true if there are records that preceede records in the current page.
50 51 52 |
# File 'lib/cursed/collection.rb', line 50 def prev_page? prev_page.any? end |