Module: Sequel::Dataset::Pagination
- Defined in:
- lib/sequel/extensions/pagination.rb
Overview
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).
Instance Method Summary collapse
- 
  
    
      #current_page  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    The current page of the dataset, starting at 1 and not 0. 
- 
  
    
      #current_page_record_count  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    Returns the number of records in the current page. 
- 
  
    
      #current_page_record_range  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    Returns the record range for the current page. 
- 
  
    
      #first_page?  ⇒ Boolean 
    
    
  
  
  
  
  
  
  
  
  
    Returns true if the current page is the first page. 
- 
  
    
      #last_page?  ⇒ Boolean 
    
    
  
  
  
  
  
  
  
  
  
    Returns true if the current page is the last page. 
- 
  
    
      #next_page  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    Returns the next page number or nil if the current page is the last page. 
- 
  
    
      #page_count  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    The number of pages in the dataset before pagination, of which this paginated dataset is one. 
- 
  
    
      #page_range  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    Returns the page range. 
- 
  
    
      #page_size  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    The number of records per page (the final page may have fewer than this number of records). 
- 
  
    
      #pagination_record_count  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    The total number of records in the dataset before pagination. 
- 
  
    
      #prev_page  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    Returns the previous page number or nil if the current page is the first. 
Instance Method Details
#current_page ⇒ Object
The current page of the dataset, starting at 1 and not 0.
| 83 84 85 | # File 'lib/sequel/extensions/pagination.rb', line 83 def current_page @opts[:current_page] end | 
#current_page_record_count ⇒ Object
Returns the number of records in the current page
| 103 104 105 106 107 108 109 110 | # File 'lib/sequel/extensions/pagination.rb', line 103 def current_page_record_count return 0 if current_page > page_count a = 1 + (current_page - 1) * page_size b = a + page_size - 1 b = pagination_record_count if b > pagination_record_count b - a + 1 end | 
#current_page_record_range ⇒ Object
Returns the record range for the current page
| 93 94 95 96 97 98 99 100 | # File 'lib/sequel/extensions/pagination.rb', line 93 def current_page_record_range return (0..0) if current_page > page_count a = 1 + (current_page - 1) * page_size b = a + page_size - 1 b = pagination_record_count if b > pagination_record_count a..b end | 
#first_page? ⇒ Boolean
Returns true if the current page is the first page
| 113 114 115 | # File 'lib/sequel/extensions/pagination.rb', line 113 def first_page? current_page == 1 end | 
#last_page? ⇒ Boolean
Returns true if the current page is the last page
| 118 119 120 | # File 'lib/sequel/extensions/pagination.rb', line 118 def last_page? current_page == page_count end | 
#next_page ⇒ Object
Returns the next page number or nil if the current page is the last page
| 123 124 125 | # File 'lib/sequel/extensions/pagination.rb', line 123 def next_page current_page < page_count ? (current_page + 1) : nil end | 
#page_count ⇒ Object
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.
| 78 79 80 | # File 'lib/sequel/extensions/pagination.rb', line 78 def page_count @opts[:page_count] end | 
#page_range ⇒ Object
Returns the page range
| 128 129 130 | # File 'lib/sequel/extensions/pagination.rb', line 128 def page_range 1..page_count end | 
#page_size ⇒ Object
The number of records per page (the final page may have fewer than this number of records).
| 71 72 73 | # File 'lib/sequel/extensions/pagination.rb', line 71 def page_size @opts[:page_size] end | 
#pagination_record_count ⇒ Object
The total number of records in the dataset before pagination.
| 88 89 90 | # File 'lib/sequel/extensions/pagination.rb', line 88 def pagination_record_count @opts[:pagination_record_count] end | 
#prev_page ⇒ Object
Returns the previous page number or nil if the current page is the first
| 133 134 135 | # File 'lib/sequel/extensions/pagination.rb', line 133 def prev_page current_page > 1 ? (current_page - 1) : nil end |