2011-02-20 13:04:18 +09:00
|
|
|
require File.join(File.dirname(__FILE__), 'active_record_relation_methods')
|
2011-02-05 22:55:38 +09:00
|
|
|
module Kaminari
|
2011-02-18 08:09:53 +09:00
|
|
|
module ActiveRecordExtension
|
2011-02-05 22:55:38 +09:00
|
|
|
extend ActiveSupport::Concern
|
|
|
|
included do
|
2011-02-17 01:22:27 +09:00
|
|
|
def self.inherited(kls) #:nodoc:
|
2011-02-05 23:26:49 +09:00
|
|
|
# TERRIBLE HORRIBLE NO GOOD VERY BAD HACK: inheritable_attributes is not yet set here on AR 3.0
|
|
|
|
unless kls.default_scoping
|
|
|
|
new_inheritable_attributes = Hash[inheritable_attributes.map do |key, value|
|
|
|
|
[key, value.duplicable? ? value.dup : value]
|
|
|
|
end]
|
|
|
|
kls.instance_variable_set('@inheritable_attributes', new_inheritable_attributes)
|
|
|
|
end
|
2011-02-11 23:34:45 +09:00
|
|
|
|
2011-02-05 22:55:38 +09:00
|
|
|
kls.class_eval do
|
2011-02-21 02:27:40 +09:00
|
|
|
include Kaminari::ConfigurationMethods
|
|
|
|
|
2011-02-17 01:22:27 +09:00
|
|
|
# Fetch the values at the specified page number
|
|
|
|
# Model.page(5)
|
2011-02-20 01:00:32 +09:00
|
|
|
scope :page, Proc.new {|num|
|
2011-02-15 18:41:49 +09:00
|
|
|
limit(default_per_page).offset(default_per_page * ([num.to_i, 1].max - 1))
|
2011-02-05 22:55:38 +09:00
|
|
|
} do
|
2011-02-20 13:04:18 +09:00
|
|
|
include Kaminari::ActiveRecordRelationMethods
|
|
|
|
include Kaminari::PageScopeMethods
|
2011-02-15 18:41:49 +09:00
|
|
|
end
|
2011-02-05 22:55:38 +09:00
|
|
|
end
|
2011-02-24 09:19:51 +01:00
|
|
|
|
|
|
|
super
|
2011-02-05 22:55:38 +09:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|