Class: Decidim::Comments::DeleteComment

Inherits:
Decidim::Command show all
Defined in:
decidim-comments/app/commands/decidim/comments/delete_comment.rb

Overview

A command with all the business logic to delete a comment

Instance Method Summary collapse

Methods inherited from Decidim::Command

call, #evaluate, #method_missing, #respond_to_missing?, #transaction

Constructor Details

#initialize(comment, current_user) ⇒ DeleteComment

Public: Initializes the command.

comment - The comment to delete. current_user - The user performing the action.


11
12
13
14
# File 'decidim-comments/app/commands/decidim/comments/delete_comment.rb', line 11

def initialize(comment, current_user)
  @comment = comment
  @current_user = current_user
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Decidim::Command

Instance Method Details

#callObject

Executes the command. Broadcasts these events:

  • :ok when everything is valid.

  • :invalid if comment isn't authored by current_user.

Returns nothing.


22
23
24
25
26
27
28
# File 'decidim-comments/app/commands/decidim/comments/delete_comment.rb', line 22

def call
  return broadcast(:invalid) unless comment.authored_by?(current_user)

  delete_comment

  broadcast(:ok)
end