1
0
Fork 0
mirror of https://github.com/kaminari/kaminari.git synced 2022-11-09 13:44:37 -05:00
kaminari--kaminari/lib/kaminari/models/page_scope_methods.rb
Akira Matsuda fe5df577f3 whitespace
2011-04-25 17:14:28 +09:00

36 lines
804 B
Ruby

module Kaminari
module PageScopeMethods
extend ActiveSupport::Concern
module InstanceMethods
# Specify the <tt>per_page</tt> value for the preceding <tt>page</tt> scope
# Model.page(3).per(10)
def per(num)
if (n = num.to_i) <= 0
self
else
limit(n).offset(offset_value / limit_value * n)
end
end
# Total number of pages
def num_pages
(total_count.to_f / limit_value).ceil
end
# Current page number
def current_page
(offset_value / limit_value) + 1
end
# First page of the collection ?
def first_page?
current_page == 1
end
# Last page of the collection?
def last_page?
current_page >= num_pages
end
end
end
end