Sha256: 18d088ffd2cc37545a369fabe0fee9f2996d8eca907f17a2c62951769a28f8ee

Contents?: true

Size: 1.07 KB

Versions: 75

Compression:

Stored size: 1.07 KB

Contents

# frozen_string_literal: true

module Decidim
  module Comments
    # This is a helper class in order to publish comment creation events
    # so that components can react to these successes and perform whatever they are required to.
    class CommentCreation
      EVENT_NAME = "decidim.comments.comment_created"

      # Publishes the event to ActiveSupport::Notifications.
      #
      # comment - The Decidim::Comments::Comment that has just been created.
      # metadatas - The hash of metadatas returned by the ContentProcessor after parsing
      #   this `comment`.
      def self.publish(comment, metadatas)
        ActiveSupport::Notifications.publish(
          EVENT_NAME,
          comment_id: comment.id,
          metadatas: metadatas
        )
      end

      # Creates a subscription to events for created comments.
      #
      # block - The block to be executed when a comment is created.
      def self.subscribe(&block)
        ActiveSupport::Notifications.subscribe(EVENT_NAME) do |_event_name, data|
          block.call(data)
        end
      end
    end
  end
end

Version data entries

75 entries across 75 versions & 1 rubygems

Version Path
decidim-comments-0.27.9 app/services/decidim/comments/comment_creation.rb
decidim-comments-0.27.8 app/services/decidim/comments/comment_creation.rb
decidim-comments-0.27.7 app/services/decidim/comments/comment_creation.rb
decidim-comments-0.27.6 app/services/decidim/comments/comment_creation.rb
decidim-comments-0.26.10 app/services/decidim/comments/comment_creation.rb
decidim-comments-0.26.9 app/services/decidim/comments/comment_creation.rb
decidim-comments-0.27.5 app/services/decidim/comments/comment_creation.rb
decidim-comments-0.26.8 app/services/decidim/comments/comment_creation.rb
decidim-comments-0.27.4 app/services/decidim/comments/comment_creation.rb
decidim-comments-0.27.3 app/services/decidim/comments/comment_creation.rb
decidim-comments-0.26.7 app/services/decidim/comments/comment_creation.rb
decidim-comments-0.26.5 app/services/decidim/comments/comment_creation.rb
decidim-comments-0.27.2 app/services/decidim/comments/comment_creation.rb
decidim-comments-0.27.1 app/services/decidim/comments/comment_creation.rb
decidim-comments-0.26.4 app/services/decidim/comments/comment_creation.rb
decidim-comments-0.27.0 app/services/decidim/comments/comment_creation.rb
decidim-comments-0.26.3 app/services/decidim/comments/comment_creation.rb
decidim-comments-0.27.0.rc2 app/services/decidim/comments/comment_creation.rb
decidim-comments-0.27.0.rc1 app/services/decidim/comments/comment_creation.rb
decidim-comments-0.26.2 app/services/decidim/comments/comment_creation.rb