12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
|
# File 'lib/commontator/acts_as_commontable.rb', line 12
def acts_as_commontable(options = {})
class_eval do
cattr_accessor :commontable_config
self.commontable_config = Commontator::CommontableConfig.new(options)
self.is_commontable = true
has_one :thread, :as => :commontable, :class_name => 'Commontator::Thread'
has_many :comments, :class_name => 'Commontator::Comment', :through => :thread
has_many :subscriptions, :class_name => 'Commontator::Subscription', :through => :thread
validates_presence_of :thread
alias_method :relation_thread, :thread
def thread
@thread ||= relation_thread
if !@thread
@thread = Commontator::Thread.new
@thread.commontable = self
end
@thread.save if !@thread.persisted? && persisted?
@thread
end
end
end
|