Module: Commontator::ActsAsCommontable::ClassMethods

Defined in:
lib/commontator/acts_as_commontable.rb

Defined Under Namespace

Modules: ThreadWithCommontator

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
# File 'lib/commontator/acts_as_commontable.rb', line 12

def acts_as_commontable(options = {})
  class_eval do
    cattr_accessor :commontable_config
    association_options = options.extract!(:dependent)
    self.commontable_config = Commontator::CommontableConfig.new(options)
    self.is_commontable = true

    has_one :thread, as: :commontable,
                     class_name: 'Commontator::Thread',
                     dependent: association_options[:dependent]

    validates_presence_of :thread

    prepend ThreadWithCommontator
  end
end