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 Model
def self.included(base)
base.has_many :moderations, as: :moderatable, dependent: :destroy
extend ActiveSupport::Concern
included do
has_many :moderations, as: :moderatable, dependent: :destroy
end
module ClassMethods
end
def moderate(*moderated_attributes)

View File

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

View File

@ -20,6 +20,7 @@ Gem::Specification.new do |spec|
spec.add_dependency "activemodel", "~> 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 "rake"