class MongoModel::Paginator
Attributes
current_page[R]
per_page[R]
total_entries[R]
Public Class Methods
new(scope, page, per_page)
click to toggle source
Calls superclass method
# File lib/mongomodel/support/paginator.rb, line 5 def initialize(scope, page, per_page) @current_page = page.to_i @per_page = per_page.to_i super(scope.offset(offset).limit(per_page)) # Try to autodetect total entries if total_entries.nil? && size < per_page && (current_page == 1 or size > 0) @total_entries = offset + size else @total_entries = scope.count end end
Public Instance Methods
next_page()
click to toggle source
# File lib/mongomodel/support/paginator.rb, line 27 def next_page current_page < total_pages ? (current_page + 1) : nil end
offset()
click to toggle source
# File lib/mongomodel/support/paginator.rb, line 35 def offset (current_page - 1) * per_page end
out_of_bounds?()
click to toggle source
# File lib/mongomodel/support/paginator.rb, line 31 def out_of_bounds? current_page > total_pages end
previous_page()
click to toggle source
# File lib/mongomodel/support/paginator.rb, line 23 def previous_page current_page > 1 ? (current_page - 1) : nil end
total_pages()
click to toggle source
# File lib/mongomodel/support/paginator.rb, line 19 def total_pages total_entries.zero? ? 1 : (total_entries / per_page.to_f).ceil end