| 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 73
73: def current_page_record_count
74: return 0 if @current_page > @page_count
75:
76: a = 1 + (@current_page - 1) * @page_size
77: b = a + @page_size - 1
78: b = @pagination_record_count if b > @pagination_record_count
79: b - a + 1
80: end
Returns the record range for the current page
# File lib/sequel/extensions/pagination.rb, line 63
63: def current_page_record_range
64: return (0..0) if @current_page > @page_count
65:
66: a = 1 + (@current_page - 1) * @page_size
67: b = a + @page_size - 1
68: b = @pagination_record_count if b > @pagination_record_count
69: a..b
70: end
Returns true if the current page is the first page
# File lib/sequel/extensions/pagination.rb, line 83
83: def first_page?
84: @current_page == 1
85: end
Returns true if the current page is the last page
# File lib/sequel/extensions/pagination.rb, line 88
88: def last_page?
89: @current_page == @page_count
90: end
Returns the next page number or nil if the current page is the last page
# File lib/sequel/extensions/pagination.rb, line 93
93: def next_page
94: current_page < page_count ? (current_page + 1) : nil
95: end
Returns the page range
# File lib/sequel/extensions/pagination.rb, line 98
98: def page_range
99: 1..page_count
100: end
Returns the previous page number or nil if the current page is the first
# File lib/sequel/extensions/pagination.rb, line 103
103: def prev_page
104: current_page > 1 ? (current_page - 1) : nil
105: end
Sets the pagination info for this paginated dataset, and returns self.
# File lib/sequel/extensions/pagination.rb, line 108
108: def set_pagination_info(page_no, page_size, record_count)
109: @current_page = page_no
110: @page_size = page_size
111: @pagination_record_count = record_count
112: @page_count = (record_count / page_size.to_f).ceil
113: self
114: end