Module: CommentableOn::Commenter

Defined in:
lib/commentable_on/commenter.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



3
4
5
6
7
8
9
10
11
# File 'lib/commentable_on/commenter.rb', line 3

def self.included(base)
  base.class_eval do
    has_many :comments, class_name: "CommentableOn::Comment", as: :commenter, dependent: :nullify do
      def commentables
        includes(:commentable).map(&:commentable)
      end
    end
  end
end

Instance Method Details

#comment_on(commentable:, body:) ⇒ Object



13
14
15
# File 'lib/commentable_on/commenter.rb', line 13

def comment_on(commentable:, body:)
  commentable.add_comment commenter: self, body: body
end

#reply_to(comment:, body:) ⇒ Object



17
18
19
# File 'lib/commentable_on/commenter.rb', line 17

def reply_to(comment:, body:)
  comment.commentable.create_reply comment: comment, commenter: self, body: body
end