Class: Decidim::Votings::Admin::UpdateBallotStyle

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

Overview

A command with the business logic to update the ballot style

Instance Method Summary collapse

Methods inherited from Command

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

Constructor Details

#initialize(form, ballot_style) ⇒ UpdateBallotStyle

Returns a new instance of UpdateBallotStyle.



8
9
10
11
# File 'decidim-elections/app/commands/decidim/votings/admin/update_ballot_style.rb', line 8

def initialize(form, ballot_style)
  @form = form
  @ballot_style = ballot_style
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. Broadcast this events:

  • :ok when everything is valid

  • :invalid when the form was not valid and could not proceed

Returns nothing.



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

def call
  return broadcast(:invalid) unless form.valid?

  begin
    update_ballot_style!
  rescue ActiveRecord::RecordNotUnique
    form.errors.add(:code, :taken)
    return broadcast(:invalid)
  end

  transaction do
    destroy_removed_ballot_style_questions!
    create_added_ballot_style_questions!
  end

  broadcast(:ok)
end