Class: Decidim::Comments::DeleteComment
- Inherits:
-
Decidim::Command
- Object
- Decidim::Command
- Decidim::Comments::DeleteComment
- 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
-
#call ⇒ Object
Executes the command.
-
#initialize(comment, current_user) ⇒ DeleteComment
constructor
Public: Initializes the command.
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 |
Instance Method Details
#call ⇒ Object
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.(current_user) delete_comment broadcast(:ok) end |