Class: Decidim::Proposals::Admin::NotifyProposalAnswer
- Inherits:
-
Command
- Object
- Command
- Decidim::Proposals::Admin::NotifyProposalAnswer
- 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
-
#call ⇒ Object
Executes the command.
-
#initialize(proposal, initial_state) ⇒ NotifyProposalAnswer
constructor
Public: Initializes the command.
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 end |
Instance Method Details
#call ⇒ Object
Executes the command. Broadcasts these events:
-
:noop when the answer is not published or the state did not changed.
-
:ok when everything is valid.
Returns nothing.
23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'app/commands/decidim/proposals/admin/notify_proposal_answer.rb', line 23 def call return broadcast(:invalid) if proposal.blank? if proposal.published_state? && state_changed? transaction do increment_score notify_followers end end broadcast(:ok) end |