Class: Decidim::Comments::CommentCreation

Inherits:
Object
  • Object
show all
Defined in:
decidim-comments/app/services/decidim/comments/comment_creation.rb

Overview

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.

Constant Summary collapse

EVENT_NAME =
"decidim.comments.comment_created"

Class Method Summary collapse

Class Method Details

.publish(comment, metadatas) ⇒ Object

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`.


15
16
17
18
19
20
21
# File 'decidim-comments/app/services/decidim/comments/comment_creation.rb', line 15

def self.publish(comment, metadatas)
  ActiveSupport::Notifications.publish(
    EVENT_NAME,
    comment_id: comment.id,
    metadatas:
  )
end

.subscribe(&block) ⇒ Object

Creates a subscription to events for created comments.

block - The block to be executed when a comment is created.



26
27
28
29
30
# File 'decidim-comments/app/services/decidim/comments/comment_creation.rb', line 26

def self.subscribe(&block)
  ActiveSupport::Notifications.subscribe(EVENT_NAME) do |_event_name, data|
    block.call(data)
  end
end