2011-02-19 23:04:18 -05:00
|
|
|
require File.join(File.dirname(__FILE__), 'mongoid_criteria_methods')
|
2011-04-19 03:05:18 -04:00
|
|
|
|
2011-02-16 01:23:41 -05:00
|
|
|
module Kaminari
|
2011-02-18 00:52:17 -05:00
|
|
|
module MongoidExtension
|
2011-02-17 18:07:23 -05:00
|
|
|
module Criteria
|
|
|
|
extend ActiveSupport::Concern
|
|
|
|
|
|
|
|
included do
|
2011-02-23 14:20:42 -05:00
|
|
|
def page(*args)
|
|
|
|
self.klass.page(*args).criteria.merge(self)
|
|
|
|
end
|
2011-02-17 18:07:23 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
module Document
|
|
|
|
extend ActiveSupport::Concern
|
2011-02-19 23:04:18 -05:00
|
|
|
include Kaminari::ConfigurationMethods
|
2011-02-17 18:07:23 -05:00
|
|
|
|
|
|
|
included do
|
|
|
|
# Fetch the values at the specified page number
|
|
|
|
# Model.page(5)
|
2011-02-19 11:00:32 -05:00
|
|
|
scope :page, Proc.new {|num|
|
2011-02-17 18:07:23 -05:00
|
|
|
limit(default_per_page).offset(default_per_page * ([num.to_i, 1].max - 1))
|
|
|
|
} do
|
2011-02-19 23:04:18 -05:00
|
|
|
include Kaminari::MongoidCriteriaMethods
|
|
|
|
include Kaminari::PageScopeMethods
|
2011-02-17 18:07:23 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2011-02-16 01:23:41 -05:00
|
|
|
end
|
|
|
|
end
|