module Sequel::Dataset::Pagination

  1. 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 2 is offset 1 * page_size).

Public Instance methods

current_page()

The current page of the dataset, starting at 1 and not 0.

[show source]
   # File lib/sequel/extensions/pagination.rb
83 def current_page
84   @opts[:current_page]
85 end
current_page_record_count()

Returns the number of records in the current page

[show source]
    # File lib/sequel/extensions/pagination.rb
103 def current_page_record_count
104   return 0 if current_page > page_count
105   
106   a = 1 + (current_page - 1) * page_size
107   b = a + page_size - 1
108   b = pagination_record_count if b > pagination_record_count
109   b - a + 1
110 end
current_page_record_range()

Returns the record range for the current page

[show source]
    # File lib/sequel/extensions/pagination.rb
 93 def current_page_record_range
 94   return (0..0) if current_page > page_count
 95   
 96   a = 1 + (current_page - 1) * page_size
 97   b = a + page_size - 1
 98   b = pagination_record_count if b > pagination_record_count
 99   a..b
100 end
first_page?()

Returns true if the current page is the first page

[show source]
    # File lib/sequel/extensions/pagination.rb
113 def first_page?
114   current_page == 1
115 end
last_page?()

Returns true if the current page is the last page

[show source]
    # File lib/sequel/extensions/pagination.rb
118 def last_page?
119   current_page == page_count
120 end
next_page()

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

[show source]
    # File lib/sequel/extensions/pagination.rb
123 def next_page
124   current_page < page_count ? (current_page + 1) : nil
125 end
page_count()

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.

[show source]
   # File lib/sequel/extensions/pagination.rb
78 def page_count
79   @opts[:page_count]
80 end
page_range()

Returns the page range

[show source]
    # File lib/sequel/extensions/pagination.rb
128 def page_range
129   1..page_count
130 end
page_size()

The number of records per page (the final page may have fewer than this number of records).

[show source]
   # File lib/sequel/extensions/pagination.rb
71 def page_size
72   @opts[:page_size]
73 end
pagination_record_count()

The total number of records in the dataset before pagination.

[show source]
   # File lib/sequel/extensions/pagination.rb
88 def pagination_record_count
89   @opts[:pagination_record_count]
90 end
prev_page()

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

[show source]
    # File lib/sequel/extensions/pagination.rb
133 def prev_page
134   current_page > 1 ? (current_page - 1) : nil
135 end