Module: Commontator::ActsAsCommontable::ClassMethods

Defined in:
lib/commontator/acts_as_commontable.rb

Instance Method Summary collapse

Instance Method Details

#acts_as_commontable(options = {}) ⇒ Object Also known as: acts_as_commentable



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/commontator/acts_as_commontable.rb', line 12

def acts_as_commontable(options = {})
  class_exec do
    association_options = options.extract!(:dependent)
    association_options[:dependent] ||= :nullify

    cattr_accessor :commontable_config
    self.commontable_config = Commontator::CommontableConfig.new(options)

    has_one :commontator_thread, association_options.merge(
      as: :commontable, class_name: 'Commontator::Thread'
    )

    prepend Commontator::BuildThread

    # Support creating acts_as_commontable records without a commontator_thread when migrating
    validates :commontator_thread, presence: true, if: -> { Commontator::Thread.table_exists? }

    self.is_commontable = true
  end
end