Class: Decidim::Proposals::Admin::NotifyProposalAnswer

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

Overview

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

Instance Method Summary collapse

Constructor Details

#initialize(proposal, initial_state) ⇒ NotifyProposalAnswer

Public: Initializes the command.

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



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

def initialize(proposal, initial_state)
  @proposal = proposal
  @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/proposals/admin/notify_proposal_answer.rb', line 23

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

  broadcast(:ok)
end