Module | Sequel::Dataset::Pagination |
In: |
lib/sequel/extensions/pagination.rb
|
Holds methods that only relate to paginated datasets. Paginated dataset have pages starting at 1 (page 1 is offset 0, page 1 is offset page_size).
current_page | [RW] | The current page of the dataset, starting at 1 and not 0. |
page_count | [RW] | The number of pages in the dataset before pagination, of which this paginated dataset is one. |
page_size | [RW] | The number of records per page (the final page may have fewer than this number of records). |
pagination_record_count | [RW] | The total number of records in the dataset before pagination. |
Returns the number of records in the current page
# File lib/sequel/extensions/pagination.rb, line 60 60: def current_page_record_count 61: return 0 if @current_page > @page_count 62: 63: a = 1 + (@current_page - 1) * @page_size 64: b = a + @page_size - 1 65: b = @pagination_record_count if b > @pagination_record_count 66: b - a + 1 67: end
Returns the record range for the current page
# File lib/sequel/extensions/pagination.rb, line 50 50: def current_page_record_range 51: return (0..0) if @current_page > @page_count 52: 53: a = 1 + (@current_page - 1) * @page_size 54: b = a + @page_size - 1 55: b = @pagination_record_count if b > @pagination_record_count 56: a..b 57: end
Returns true if the current page is the first page
# File lib/sequel/extensions/pagination.rb, line 70 70: def first_page? 71: @current_page == 1 72: end
Returns true if the current page is the last page
# File lib/sequel/extensions/pagination.rb, line 75 75: def last_page? 76: @current_page == @page_count 77: end
Returns the next page number or nil if the current page is the last page
# File lib/sequel/extensions/pagination.rb, line 80 80: def next_page 81: current_page < page_count ? (current_page + 1) : nil 82: end
Returns the page range
# File lib/sequel/extensions/pagination.rb, line 85 85: def page_range 86: 1..page_count 87: end
Returns the previous page number or nil if the current page is the first
# File lib/sequel/extensions/pagination.rb, line 90 90: def prev_page 91: current_page > 1 ? (current_page - 1) : nil 92: end
Sets the pagination info for this paginated dataset, and returns self.
# File lib/sequel/extensions/pagination.rb, line 95 95: def set_pagination_info(page_no, page_size, record_count) 96: @current_page = page_no 97: @page_size = page_size 98: @pagination_record_count = record_count 99: @page_count = (record_count / page_size.to_f).ceil 100: self 101: end