Sha256: c70b6f5c00382d5dfb9212253822b98b1c8358578915124696ad776484632673

Contents?: true

Size: 1.19 KB

Versions: 6

Compression:

Stored size: 1.19 KB

Contents

# frozen_string_literal: true

require "active_support/concern"

module Decidim
  module Comments
    # Shared behaviour for commentable models.
    module Commentable
      extend ActiveSupport::Concern

      included do
        has_many :comments, as: :commentable, foreign_key: "decidim_commentable_id", foreign_type: "decidim_commentable_type", class_name: "Decidim::Comments::Comment"

        # Public: Whether the object's comments are visible or not.
        def commentable?
          true
        end

        # Public: Whether the object can have new comments or not.
        def accepts_new_comments?
          true
        end

        # Public: Whether the object's comments can have alignment or not. It enables the
        # alignment selector in the add new comment form.
        def comments_have_alignment?
          false
        end

        # Public: Whether the object's comments can have have votes or not. It enables the
        # upvote and downvote buttons for comments.
        def comments_have_votes?
          false
        end

        # Public: Identifies the commentable type in the API.
        def commentable_type
          self.class.name
        end
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 2 rubygems

Version Path
decidim-comments-0.3.2 lib/decidim/comments/commentable.rb
decidim-0.3.2 decidim-comments/lib/decidim/comments/commentable.rb
decidim-comments-0.3.1 lib/decidim/comments/commentable.rb
decidim-0.3.1 decidim-comments/lib/decidim/comments/commentable.rb
decidim-comments-0.3.0 lib/decidim/comments/commentable.rb
decidim-0.3.0 decidim-comments/lib/decidim/comments/commentable.rb