Class: PackAPI::Pagination::Paginator
- Inherits:
-
Object
- Object
- PackAPI::Pagination::Paginator
- Defined in:
- lib/pack_api/pagination/paginator.rb
Constant Summary collapse
- DEFAULT_PER_PAGE =
20
Instance Attribute Summary collapse
- #metadata ⇒ Object
- #offset ⇒ Object
- #per_page ⇒ Object
- #query ⇒ Object
- #sort ⇒ Object
- #total_items ⇒ Object
Instance Method Summary collapse
-
#current_page_cursor ⇒ Object
Represents a single page of results in the current record set– the “current” page.
-
#first_page_cursor ⇒ Object
Represents a single page of results in the current record set– the “first” N results.
-
#item_range ⇒ Object
The range of items included in the results.
-
#last_page_cursor ⇒ Object
Represents a single page of results in the current record set– the “last” N results.
- #limit ⇒ Object
-
#next_page_cursor ⇒ Object
Represents a single page of results in the current record set– the “next” N results.
-
#previous_page_cursor ⇒ Object
Represents a single page of results in the current record set– the “previous” N results.
-
#recordset_cursor ⇒ Object
Represent the record set as a cursor– this captures the current search criteria (filters, sort, etc.).
Instance Attribute Details
#metadata ⇒ Object
32 33 34 |
# File 'lib/pack_api/pagination/paginator.rb', line 32 def @metadata end |
#offset ⇒ Object
32 33 34 |
# File 'lib/pack_api/pagination/paginator.rb', line 32 def offset @offset end |
#per_page ⇒ Object
32 33 34 |
# File 'lib/pack_api/pagination/paginator.rb', line 32 def per_page @per_page end |
#query ⇒ Object
32 33 34 |
# File 'lib/pack_api/pagination/paginator.rb', line 32 def query @query end |
#sort ⇒ Object
32 33 34 |
# File 'lib/pack_api/pagination/paginator.rb', line 32 def sort @sort end |
#total_items ⇒ Object
32 33 34 |
# File 'lib/pack_api/pagination/paginator.rb', line 32 def total_items @total_items end |
Instance Method Details
#current_page_cursor ⇒ Object
Represents a single page of results in the current record set– the “current” page
56 57 58 |
# File 'lib/pack_api/pagination/paginator.rb', line 56 def current_page_cursor make_cursor(current_page_cursor_params) end |
#first_page_cursor ⇒ Object
Represents a single page of results in the current record set– the “first” N results
74 75 76 |
# File 'lib/pack_api/pagination/paginator.rb', line 74 def first_page_cursor make_cursor(first_page_params) end |
#item_range ⇒ Object
The range of items included in the results.
38 39 40 41 42 43 44 45 46 |
# File 'lib/pack_api/pagination/paginator.rb', line 38 def item_range return 0..0 if per_page != :all && per_page.zero? lower_bound = offset + 1 upper_bound = per_page == :all ? total_items : [(offset + per_page), total_items].min lower_bound..upper_bound end |
#last_page_cursor ⇒ Object
Represents a single page of results in the current record set– the “last” N results
80 81 82 |
# File 'lib/pack_api/pagination/paginator.rb', line 80 def last_page_cursor make_cursor(last_page_params) end |
#limit ⇒ Object
84 85 86 87 88 |
# File 'lib/pack_api/pagination/paginator.rb', line 84 def limit return nil if per_page == :all per_page end |
#next_page_cursor ⇒ Object
Represents a single page of results in the current record set– the “next” N results
62 63 64 |
# File 'lib/pack_api/pagination/paginator.rb', line 62 def next_page_cursor make_cursor(next_page_params) end |
#previous_page_cursor ⇒ Object
Represents a single page of results in the current record set– the “previous” N results
68 69 70 |
# File 'lib/pack_api/pagination/paginator.rb', line 68 def previous_page_cursor make_cursor(previous_page_params) end |
#recordset_cursor ⇒ Object
Represent the record set as a cursor– this captures the current search criteria (filters, sort, etc.)
50 51 52 |
# File 'lib/pack_api/pagination/paginator.rb', line 50 def recordset_cursor make_cursor(recordset_cursor_params) end |