Class: Decidim::Elections::Admin::UpdateActionStatus

Inherits:
Command
  • Object
show all
Defined in:
decidim-elections/app/commands/decidim/elections/admin/update_action_status.rb

Overview

This command updates the status of the action and the election if it got changed

Instance Method Summary collapse

Methods inherited from Command

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

Constructor Details

#initialize(action) ⇒ UpdateActionStatus

Public: Initializes the command.

action - The pending action to be updated



11
12
13
# File 'decidim-elections/app/commands/decidim/elections/admin/update_action_status.rb', line 11

def initialize(action)
  @action = action
end

Dynamic Method Handling

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

Instance Method Details

#callObject

Update the statuses of the action and the election if pending message status got changed.

Broadcasts :ok if successful, :invalid otherwise.



18
19
20
21
22
23
24
25
26
27
# File 'decidim-elections/app/commands/decidim/elections/admin/update_action_status.rb', line 18

def call
  return broadcast(:ok) unless action.pending?

  transaction do
    update_pending_message_status
    update_election_status if action.accepted?
  end

  broadcast(:ok)
end