| Module | Sequel::Dataset::Pagination |
| In: |
lib/sequel_core/dataset/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_core/dataset/pagination.rb, line 52
52: def current_page_record_count
53: return 0 if @current_page > @page_count
54:
55: a = 1 + (@current_page - 1) * @page_size
56: b = a + @page_size - 1
57: b = @pagination_record_count if b > @pagination_record_count
58: b - a + 1
59: end
Returns the record range for the current page
# File lib/sequel_core/dataset/pagination.rb, line 42
42: def current_page_record_range
43: return (0..0) if @current_page > @page_count
44:
45: a = 1 + (@current_page - 1) * @page_size
46: b = a + @page_size - 1
47: b = @pagination_record_count if b > @pagination_record_count
48: a..b
49: end
Returns true if the current page is the first page
# File lib/sequel_core/dataset/pagination.rb, line 62
62: def first_page?
63: @current_page == 1
64: end
Returns true if the current page is the last page
# File lib/sequel_core/dataset/pagination.rb, line 67
67: def last_page?
68: @current_page == @page_count
69: end
Returns the next page number or nil if the current page is the last page
# File lib/sequel_core/dataset/pagination.rb, line 72
72: def next_page
73: current_page < page_count ? (current_page + 1) : nil
74: end
Returns the page range
# File lib/sequel_core/dataset/pagination.rb, line 77
77: def page_range
78: 1..page_count
79: end
Returns the previous page number or nil if the current page is the first
# File lib/sequel_core/dataset/pagination.rb, line 82
82: def prev_page
83: current_page > 1 ? (current_page - 1) : nil
84: end
Sets the pagination info for this paginated dataset, and returns self.
# File lib/sequel_core/dataset/pagination.rb, line 87
87: def set_pagination_info(page_no, page_size, record_count)
88: @current_page = page_no
89: @page_size = page_size
90: @pagination_record_count = record_count
91: @page_count = (record_count / page_size.to_f).ceil
92: self
93: end