Module: ActsAsAble::Commentable::InstanceMethods

Defined in:
lib/acts_as_able/commentable.rb

Instance Method Summary collapse

Instance Method Details

#comment_countObject



32
33
34
# File 'lib/acts_as_able/commentable.rb', line 32

def comment_count
  self.commenters.count
end

#commenters_by_type(commenter_type, options = {}) ⇒ Object



36
37
38
39
40
41
42
43
# File 'lib/acts_as_able/commentable.rb', line 36

def commenters_by_type(commenter_type, options = {})
  ids = Comment.
    where('commentable_id' => self.id,
          'commentable_type' => class_name(self),
          'commenter_type' => commenter_type.name
  ).pluck('commenter_id')
  return commenter_type.where("id in (?)", ids)
end

#root_commentersObject



18
19
20
# File 'lib/acts_as_able/commentable.rb', line 18

def root_commenters 
  self.commenters.where(parent_id: nil)
end

#root_commenters_by_type(commenter_type, options = {}) ⇒ Object



22
23
24
25
26
27
28
29
30
# File 'lib/acts_as_able/commentable.rb', line 22

def root_commenters_by_type(commenter_type, options= {})
  ids = Comment.
    where('commentable_id' => self.id,
          'commentable_type' => class_name(self),
          'commenter_type' => commenter_type.name,
          'parent_id' => nil
  ).pluck('commenter_id')
  return commenter_type.where("id in (?)", ids)
end