Public Instance methods
each_page(page_size)
Yields a paginated dataset for each page and returns the receiver. Does a count to find the total number of records for this dataset. Returns an enumerator if no block is given.
[show source]
# File lib/sequel/extensions/pagination.rb 55 def each_page(page_size) 56 raise(Error, "You cannot paginate a dataset that already has a limit") if @opts[:limit] 57 return to_enum(:each_page, page_size) unless defined?(yield) 58 record_count = count 59 total_pages = (record_count / page_size.to_f).ceil 60 (1..total_pages).each{|page_no| yield paginate(page_no, page_size, record_count)} 61 self 62 end
paginate(page_no, page_size, record_count=nil)
Returns a paginated dataset. The returned dataset is limited to the page size at the correct offset, and extended with the Pagination module. If a record count is not provided, does a count of total number of records for this dataset.
[show source]
# File lib/sequel/extensions/pagination.rb 40 def paginate(page_no, page_size, record_count=nil) 41 raise(Error, "You cannot paginate a dataset that already has a limit") if @opts[:limit] 42 43 record_count ||= count 44 page_count = (record_count / page_size.to_f).ceil 45 page_count = 1 if page_count == 0 46 47 limit(page_size, (page_no - 1) * page_size). 48 with_extend(Dataset::Pagination). 49 clone(:page_size=>page_size, :current_page=>page_no, :pagination_record_count=>record_count, :page_count=>page_count) 50 end