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

Inherits:
Command
  • Object
show all
Defined in:
decidim-proposals/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

Methods inherited from Command

call, #evaluate, #method_missing, #respond_to_missing?, #transaction, #with_events

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 'decidim-proposals/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

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Decidim::Command

Instance Method Details

#callObject

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 'decidim-proposals/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