Use ActiveSupport::Concern for included modules

master
Guillaume DOTT 2013-11-27 16:35:17 +01:00
parent 6257d03e45
commit 31090e74cc
3 changed files with 16 additions and 8 deletions

View File

@ -1,7 +1,14 @@
require 'active_support/concern'
module TheModerator module TheModerator
module Model module Model
def self.included(base) extend ActiveSupport::Concern
base.has_many :moderations, as: :moderatable, dependent: :destroy
included do
has_many :moderations, as: :moderatable, dependent: :destroy
end
module ClassMethods
end end
def moderate(*moderated_attributes) def moderate(*moderated_attributes)

View File

@ -1,13 +1,13 @@
require 'active_support/concern'
module TheModerator module TheModerator
module ModerationModel module ModerationModel
def self.included(base) extend ActiveSupport::Concern
base.send :extend, ClassMethods
base.class_eval do included do
belongs_to :moderatable, polymorphic: true belongs_to :moderatable, polymorphic: true
serialize :data serialize :data
end end
end
module ClassMethods module ClassMethods
end end

View File

@ -20,6 +20,7 @@ Gem::Specification.new do |spec|
spec.add_dependency "activemodel", "~> 3.2.0" spec.add_dependency "activemodel", "~> 3.2.0"
spec.add_dependency "activerecord", "~> 3.2.0" spec.add_dependency "activerecord", "~> 3.2.0"
spec.add_dependency "activesupport", "~> 3.2.0"
spec.add_development_dependency "bundler", "~> 1.3" spec.add_development_dependency "bundler", "~> 1.3"
spec.add_development_dependency "rake" spec.add_development_dependency "rake"