Module: Sequel::Dataset::Pagination

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

current_page_record_count current_page_record_range first_page? last_page? next_page page_range prev_page set_pagination_info

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

current_page_record_count()

Returns the number of records in the current page

[Source]

        # File lib/sequel/extensions/pagination.rb, line 56
    56:       def current_page_record_count
    57:         return 0 if @current_page > @page_count
    58:
    59:         a = 1 + (@current_page - 1) * @page_size
    60:         b = a + @page_size - 1
    61:         b = @pagination_record_count if b > @pagination_record_count
    62:         b - a + 1
    63:       end

current_page_record_range()

Returns the record range for the current page

[Source]

        # File lib/sequel/extensions/pagination.rb, line 46
    46:       def current_page_record_range
    47:         return (0..0) if @current_page > @page_count
    48:
    49:         a = 1 + (@current_page - 1) * @page_size
    50:         b = a + @page_size - 1
    51:         b = @pagination_record_count if b > @pagination_record_count
    52:         a..b
    53:       end

first_page?()

Returns true if the current page is the first page

[Source]

        # File lib/sequel/extensions/pagination.rb, line 66
    66:       def first_page?
    67:         @current_page == 1
    68:       end

last_page?()

Returns true if the current page is the last page

[Source]

        # File lib/sequel/extensions/pagination.rb, line 71
    71:       def last_page?
    72:         @current_page == @page_count
    73:       end

next_page()

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

[Source]

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

page_range()

Returns the page range

[Source]

        # File lib/sequel/extensions/pagination.rb, line 81
    81:       def page_range
    82:         1..page_count
    83:       end

prev_page()

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

[Source]

        # File lib/sequel/extensions/pagination.rb, line 86
    86:       def prev_page
    87:         current_page > 1 ? (current_page - 1) : nil
    88:       end

set_pagination_info(page_no, page_size, record_count)

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

[Source]

        # File lib/sequel/extensions/pagination.rb, line 91
    91:       def set_pagination_info(page_no, page_size, record_count)
    92:         @current_page = page_no
    93:         @page_size = page_size
    94:         @pagination_record_count = record_count
    95:         @page_count = (record_count / page_size.to_f).ceil
    96:         self
    97:       end

[Validate]