Sha256: 4c6f2bd07d10f278d7580f70b0202245443a7032c1dff8c2a767804866536b4a

Contents?: true

Size: 1.1 KB

Versions: 6

Compression:

Stored size: 1.1 KB

Contents

require_relative 'commontator_config'

module Commontator::ActsAsCommontator
  def self.included(base)
    base.class_attribute :is_commontator
    base.is_commontator = false
    base.extend(ClassMethods)
  end

  module ClassMethods
    def acts_as_commontator(options = {})
      class_exec do
        association_options = options.extract!(:dependent)
        association_options[:dependent] ||= :destroy

        cattr_accessor :commontator_config
        self.commontator_config = Commontator::CommontatorConfig.new(options)

        has_many :commontator_comments, association_options.merge(
          as: :creator, class_name: 'Commontator::Comment'
        )
        has_many :commontator_subscriptions, association_options.merge(
          as: :subscriber, class_name: 'Commontator::Subscription'
        )

        self.is_commontator = true
      end
    end

    alias_method :acts_as_commonter, :acts_as_commontator
    alias_method :acts_as_commentator, :acts_as_commontator
    alias_method :acts_as_commenter, :acts_as_commontator
  end
end

ActiveRecord::Base.send :include, Commontator::ActsAsCommontator

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
commontator-6.1.1 lib/commontator/acts_as_commontator.rb
commontator-6.1.0 lib/commontator/acts_as_commontator.rb
commontator-6.0.1 lib/commontator/acts_as_commontator.rb
commontator-6.0.0 lib/commontator/acts_as_commontator.rb
commontator-6.0.0.pre.2 lib/commontator/acts_as_commontator.rb
commontator-6.0.0.pre.1 lib/commontator/acts_as_commontator.rb