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 74
74:       def current_page_record_count
75:         return 0 if @current_page > @page_count
76:         
77:         a = 1 + (@current_page - 1) * @page_size
78:         b = a + @page_size - 1
79:         b = @pagination_record_count if b > @pagination_record_count
80:         b - a + 1
81:       end

Returns the record range for the current page

[Source]

    # File lib/sequel/extensions/pagination.rb, line 64
64:       def current_page_record_range
65:         return (0..0) if @current_page > @page_count
66:         
67:         a = 1 + (@current_page - 1) * @page_size
68:         b = a + @page_size - 1
69:         b = @pagination_record_count if b > @pagination_record_count
70:         a..b
71:       end

Returns true if the current page is the first page

[Source]

    # File lib/sequel/extensions/pagination.rb, line 84
84:       def first_page?
85:         @current_page == 1
86:       end

Returns true if the current page is the last page

[Source]

    # File lib/sequel/extensions/pagination.rb, line 89
89:       def last_page?
90:         @current_page == @page_count
91:       end

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

[Source]

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

Returns the page range

[Source]

     # File lib/sequel/extensions/pagination.rb, line 99
 99:       def page_range
100:         1..page_count
101:       end

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

[Source]

     # File lib/sequel/extensions/pagination.rb, line 104
104:       def prev_page
105:         current_page > 1 ? (current_page - 1) : nil
106:       end

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

[Source]

     # File lib/sequel/extensions/pagination.rb, line 109
109:       def set_pagination_info(page_no, page_size, record_count)
110:         @current_page = page_no
111:         @page_size = page_size
112:         @pagination_record_count = record_count
113:         @page_count = (record_count / page_size.to_f).ceil
114:         @page_count = 1 if @page_count == 0
115:         self
116:       end

[Validate]