Class: Decidim::Comments::UpdateComment

Inherits:
Rectify::Command
  • Object
show all
Defined in:
app/commands/decidim/comments/update_comment.rb

Overview

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

Instance Method Summary collapse

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 'app/commands/decidim/comments/update_comment.rb', line 12

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

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 '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