Sha256: 07b38bb9055966cd90a5670fd5db6ecfb49eaa71f9de0a7daa8d885cabd46ecd

Contents?: true

Size: 497 Bytes

Versions: 1

Compression:

Stored size: 497 Bytes

Contents

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

    def add_comment(commenter:, body:)
      comment = CommentableOn::Comment.new(commentable: self, commenter: commenter, body: body)
      comment.save
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
commentable_on-0.1.0 lib/commentable_on/commentable.rb