1
0
Fork 0
mirror of https://github.com/kaminari/kaminari.git synced 2022-11-09 13:44:37 -05:00

Use AS::Concern to extend class methods

This commit is contained in:
Akira Matsuda 2015-02-11 15:34:35 +09:00
parent cc36733961
commit 05ff5615fa
2 changed files with 15 additions and 16 deletions

View file

@ -3,16 +3,16 @@ require 'kaminari/models/active_record_model_extension'
module Kaminari
module ActiveRecordExtension
extend ActiveSupport::Concern
included do
# Future subclasses will pick up the model extension
class << self
def inherited_with_kaminari(kls) #:nodoc:
inherited_without_kaminari kls
kls.send(:include, Kaminari::ActiveRecordModelExtension) if kls.superclass == ::ActiveRecord::Base
end
alias_method_chain :inherited, :kaminari
end
module ClassMethods
# Future subclasses will pick up the model extension
def inherited(kls) #:nodoc:
super
kls.send(:include, Kaminari::ActiveRecordModelExtension) if kls.superclass == ::ActiveRecord::Base
end
end
included do
# Existing subclasses pick up the model extension as well
self.descendants.each do |kls|
kls.send(:include, Kaminari::ActiveRecordModelExtension) if kls.superclass == ::ActiveRecord::Base

View file

@ -13,14 +13,13 @@ module Kaminari
include Kaminari::MongoidCriteriaMethods
include Kaminari::PageScopeMethods
end
end
class << self
def inherited_with_kaminari(kls)
inherited_without_kaminari(kls)
kls.send(:include, Kaminari::MongoidExtension::Document.dup)
end
alias_method_chain :inherited, :kaminari
end unless respond_to?(:inherited_with_kaminari)
module ClassMethods
def inherited(kls)
super
kls.send(:include, Kaminari::MongoidExtension::Document.dup)
end
end
end
end