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).

Methods

Attributes

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. Empty datasets are considered to have a single page.
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.

Public Instance methods

Returns the number of records in the current page

[Source]

    # File lib/sequel/extensions/pagination.rb, line 90
90:       def current_page_record_count
91:         return 0 if @current_page > @page_count
92:         
93:         a = 1 + (@current_page - 1) * @page_size
94:         b = a + @page_size - 1
95:         b = @pagination_record_count if b > @pagination_record_count
96:         b - a + 1
97:       end

Returns the record range for the current page

[Source]

    # File lib/sequel/extensions/pagination.rb, line 80
80:       def current_page_record_range
81:         return (0..0) if @current_page > @page_count
82:         
83:         a = 1 + (@current_page - 1) * @page_size
84:         b = a + @page_size - 1
85:         b = @pagination_record_count if b > @pagination_record_count
86:         a..b
87:       end

Returns true if the current page is the first page

[Source]

     # File lib/sequel/extensions/pagination.rb, line 100
100:       def first_page?
101:         @current_page == 1
102:       end

Returns true if the current page is the last page

[Source]

     # File lib/sequel/extensions/pagination.rb, line 105
105:       def last_page?
106:         @current_page == @page_count
107:       end

Returns the next page number or nil if the current page is the last page

[Source]

     # File lib/sequel/extensions/pagination.rb, line 110
110:       def next_page
111:         current_page < page_count ? (current_page + 1) : nil
112:       end

Returns the page range

[Source]

     # File lib/sequel/extensions/pagination.rb, line 115
115:       def page_range
116:         1..page_count
117:       end

Returns the previous page number or nil if the current page is the first

[Source]

     # File lib/sequel/extensions/pagination.rb, line 120
120:       def prev_page
121:         current_page > 1 ? (current_page - 1) : nil
122:       end

Sets the pagination info for this paginated dataset, and returns self.

[Source]

     # File lib/sequel/extensions/pagination.rb, line 125
125:       def set_pagination_info(page_no, page_size, record_count)
126:         @current_page = page_no
127:         @page_size = page_size
128:         @pagination_record_count = record_count
129:         @page_count = (record_count / page_size.to_f).ceil
130:         @page_count = 1 if @page_count == 0
131:         self
132:       end

[Validate]