Class: Decidim::Votings::CreatePollingStationResults

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

Overview

A command with all the business logic when creating results for a polling station

Instance Method Summary collapse

Methods inherited from Command

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

Constructor Details

#initialize(form, closure) ⇒ CreatePollingStationResults

Public: Initializes the command.

form - A form object with the params. closure - A closure object.



11
12
13
14
# File 'decidim-elections/app/commands/decidim/votings/create_polling_station_results.rb', line 11

def initialize(form, closure)
  @form = form
  @closure = closure
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:

  • :ok when everything is valid.

  • :invalid if the form was not valid and we could not proceed.

Returns nothing.



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'decidim-elections/app/commands/decidim/votings/create_polling_station_results.rb', line 22

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

  transaction do
    form.ballot_results.attributes.compact.each do |ballot_result|
      create_ballot_result_for!(ballot_result)
    end

    form.answer_results.each do |answer_result|
      create_answer_result_for!(answer_result)
    end

    form.question_results.each do |question_result|
      create_question_result_for!(question_result)
    end

    closure.certificate_phase!
  end

  broadcast(:ok)
end