class ROM::SQL::Plugin::Pagination::Pager
Pager
object provides the underlying pagination API for relations
@api public
Public Instance Methods
at(dataset, current_page, per_page = self.per_page)
click to toggle source
@api private
# File lib/rom/sql/plugin/pagination.rb, line 98 def at(dataset, current_page, per_page = self.per_page) current_page = current_page.to_i per_page = per_page.to_i self.class.new( dataset.offset((current_page-1)*per_page).limit(per_page), current_page: current_page, per_page: per_page ) end
first_in_page()
click to toggle source
Return one-based index of first tuple in page
@return [Integer]
@api public
# File lib/rom/sql/plugin/pagination.rb, line 82 def first_in_page ((current_page - 1) * per_page) + 1 end
last_in_page()
click to toggle source
Return one-based index of last tuple in page
@return [Integer]
@api public
# File lib/rom/sql/plugin/pagination.rb, line 91 def last_in_page return total if current_page == total_pages current_page * per_page end
next_page()
click to toggle source
Return next page number
@example
users.page(2).pager.next_page # => 3
@return [Integer]
@api public
# File lib/rom/sql/plugin/pagination.rb, line 40 def next_page num = current_page + 1 num if total_pages >= num end
prev_page()
click to toggle source
Return previous page number
@example
users.page(2).pager.prev_page # => 1
@return [Integer]
@api public
# File lib/rom/sql/plugin/pagination.rb, line 54 def prev_page num = current_page - 1 num if num > 0 end
total()
click to toggle source
Return total number of tuples
@return [Integer]
@api public
# File lib/rom/sql/plugin/pagination.rb, line 64 def total dataset.unlimited.count end
total_pages()
click to toggle source
Return total number of pages
@return [Integer]
@api public
# File lib/rom/sql/plugin/pagination.rb, line 73 def total_pages (total / per_page.to_f).ceil end