Class: Decidim::Elections::Admin::SetupElection

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

Overview

This command gets called when a election is setup from the admin panel.

Instance Method Summary collapse

Constructor Details

#initialize(form) ⇒ SetupElection

Public: Initializes the command.

form - A SetupForm object with the information needed to setup the election


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

def initialize(form)
  @form = form
end

Instance Method Details

#callObject

Public: Setup the Election.

Broadcasts :ok if setup, :invalid otherwise.


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

def call
  return broadcast(:invalid) if form.invalid?

  transaction do
    log_action
    update_election
    notify_trustee_about_election
    setup_election
  end

  broadcast(:ok, election)
rescue StandardError => e
  broadcast(:invalid, e.message)
end