Class: Decidim::EnhancedTextwork::Admin::NotifyParagraphAnswer

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

Overview

A command to notify about the change of the published state for a paragraph.

Instance Method Summary collapse

Constructor Details

#initialize(paragraph, initial_state) ⇒ NotifyParagraphAnswer

Public: Initializes the command.

paragraph - The paragraph to write the answer for. initial_state - The paragraph state before the current process.



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

def initialize(paragraph, initial_state)
  @paragraph = paragraph
  @initial_state = initial_state.to_s
end

Instance Method Details

#callObject

Executes the command. Broadcasts these events:

  • :noop when the answer is not published or the state didn't changed.

  • :ok when everything is valid.

Returns nothing.



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

def call
  if paragraph.published_state? && state_changed?
    transaction do
      increment_score
      notify_followers
    end
  end

  broadcast(:ok)
end