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.(: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
validates :commontator_thread, presence: true, if: -> { Commontator::Thread.table_exists? }
self.is_commontable = true
end
end
|