Class: Decidim::Votings::Admin::CreatePollingOfficer
- Defined in:
- decidim-elections/app/commands/decidim/votings/admin/create_polling_officer.rb
Overview
A command with the business logic to create a new polling officer
Instance Method Summary collapse
-
#call ⇒ Object
Executes the command.
-
#initialize(form, current_user, voting) ⇒ CreatePollingOfficer
constructor
Public: Initializes the command.
Methods inherited from Command
call, #evaluate, #method_missing, #respond_to_missing?, #transaction, #with_events
Constructor Details
#initialize(form, current_user, voting) ⇒ CreatePollingOfficer
Public: Initializes the command.
form - A form object with the params current_user - The user creating the polling officer voting - The Voting that will hold the polling officer
13 14 15 16 17 |
# File 'decidim-elections/app/commands/decidim/votings/admin/create_polling_officer.rb', line 13 def initialize(form, current_user, voting) @form = form @current_user = current_user @voting = voting end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class Decidim::Command
Instance Method Details
#call ⇒ Object
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.
25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'decidim-elections/app/commands/decidim/votings/admin/create_polling_officer.rb', line 25 def call return broadcast(:invalid) if form.invalid? ActiveRecord::Base.transaction do user = retrieve_or_invite_user create_polling_officer(user) end broadcast(:ok) rescue ActiveRecord::RecordInvalid form.errors.add(:email, :taken) broadcast(:invalid) end |