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/active_record_extension.rb

33 lines
1.1 KiB
Ruby
Raw Normal View History

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:
# 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-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)
scope :page, Proc.new {|num|
limit(default_per_page).offset(default_per_page * ([num.to_i, 1].max - 1))
2011-02-05 22:55:38 +09:00
} do
include Kaminari::ActiveRecordRelationMethods
include Kaminari::PageScopeMethods
end
2011-02-05 22:55:38 +09:00
end
super
2011-02-05 22:55:38 +09:00
end
end
end
end