mirror of
https://github.com/kaminari/kaminari.git
synced 2022-11-09 13:44:37 -05:00
3cf929f7d0
now Kaminari can live together with associations named `page` and models having method named `page`
33 lines
869 B
Ruby
33 lines
869 B
Ruby
require 'kaminari/models/mongoid_criteria_methods'
|
|
|
|
module Kaminari
|
|
module MongoidExtension
|
|
module Criteria
|
|
extend ActiveSupport::Concern
|
|
|
|
included do
|
|
class_eval <<-RUBY, __FILE__, __LINE__ + 1
|
|
def #{Kaminari.config.page_method_name}(*args)
|
|
super(*args).criteria.merge(self)
|
|
end
|
|
RUBY
|
|
end
|
|
end
|
|
|
|
module Document
|
|
extend ActiveSupport::Concern
|
|
include Kaminari::ConfigurationMethods
|
|
|
|
included do
|
|
# Fetch the values at the specified page number
|
|
# Model.page(5)
|
|
scope Kaminari.config.page_method_name, Proc.new {|num|
|
|
limit(default_per_page).offset(default_per_page * ([num.to_i, 1].max - 1))
|
|
} do
|
|
include Kaminari::MongoidCriteriaMethods
|
|
include Kaminari::PageScopeMethods
|
|
end
|
|
end
|
|
end
|
|
end
|
|
end
|