Class: Decidim::Comments::UpdateComment

Inherits:
Decidim::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, form) ⇒ UpdateComment

Public: Initializes the command.

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



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

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

Instance Method Details

#callObject

Executes the command. Broadcasts these events:

  • :ok when everything is valid.

  • :invalid if the form was not valid and we could not proceed.

Returns nothing.



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

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

  with_events do
    update_comment
  end

  broadcast(:ok)
end