Class: Decidim::EnhancedTextwork::Admin::AnswerParagraph

Inherits:
Rectify::Command
  • Object
show all
Defined in:
app/commands/decidim/enhanced_textwork/admin/answer_paragraph.rb

Overview

A command with all the business logic when an admin answers a paragraph.

Instance Method Summary collapse

Constructor Details

#initialize(form, paragraph) ⇒ AnswerParagraph

Public: Initializes the command.

form - A form object with the params. paragraph - The paragraph to write the answer for.



12
13
14
15
# File 'app/commands/decidim/enhanced_textwork/admin/answer_paragraph.rb', line 12

def initialize(form, paragraph)
  @form = form
  @paragraph = paragraph
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.



23
24
25
26
27
28
29
30
31
32
33
34
# File 'app/commands/decidim/enhanced_textwork/admin/answer_paragraph.rb', line 23

def call
  return broadcast(:invalid) if form.invalid?

  store_initial_paragraph_state

  transaction do
    answer_paragraph
    notify_paragraph_answer
  end

  broadcast(:ok)
end