Sha256: a7c98cc94b5170cf4eb46fb55fc8592dcb613f1a3bef104d50c3589d12ef7505

Contents?: true

Size: 568 Bytes

Versions: 2

Compression:

Stored size: 568 Bytes

Contents

module CommentableOn
  module Commenter
    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

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

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

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
commentable_on-1.1.0 lib/commentable_on/commenter.rb
commentable_on-1.0.0 lib/commentable_on/commenter.rb