Class: Decidim::Comments::UpdateComment

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

Overview

A command with all the business logic to update an existing comment

Instance Method Summary collapse

Methods inherited from Decidim::Command

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

Constructor Details

#initialize(comment, current_user, form) ⇒ UpdateComment

Public: Initializes the command.

comment - Decidim::Comments::Comment current_user - Decidim::User form - A form object with the params.


12
13
14
15
16
# File 'decidim-comments/app/commands/decidim/comments/update_comment.rb', line 12

def initialize(comment, current_user, form)
  @comment = comment
  @current_user = current_user
  @form = form
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 the form wasn't valid and we couldn't proceed.

Returns nothing.


24
25
26
27
28
29
30
# File 'decidim-comments/app/commands/decidim/comments/update_comment.rb', line 24

def call
  return broadcast(:invalid) if form.invalid? || !comment.authored_by?(current_user)

  update_comment

  broadcast(:ok)
end