Module: Mongoid::Commentable

Extended by:
ActiveSupport::Concern
Defined in:
lib/mongoid/commentable.rb

Defined Under Namespace

Modules: ClassMethods

Instance Method Summary collapse

Instance Method Details

#branch_for(comment_id) ⇒ Object



33
34
35
# File 'lib/mongoid/commentable.rb', line 33

def branch_for(comment_id)
  comments.select{|i| i.path =~ Regexp.new('^' + comments.find(comment_id).path)}
end

#comments_list(sort = :asc) ⇒ Object



25
26
27
28
29
30
31
# File 'lib/mongoid/commentable.rb', line 25

def comments_list(sort=:asc)
  if Comment.respond_to?(sort)
    comments.send(sort,:path)
  else
    raise ArgumentError, "Wrong argument!"
  end
end

#create_comment!(params) ⇒ Object



19
20
21
22
23
# File 'lib/mongoid/commentable.rb', line 19

def create_comment!(params)
  comment = comments.create!(params)
  comment.path = comment.parent ? comments.find(comment.parent).path + '.' + comment.id.to_s : "root."+comment.id.to_s
  comment
end