Class: Decidim::Votings::Admin::CreateBallotStyle

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

Overview

A command with the business logic to create 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) ⇒ CreateBallotStyle

Returns a new instance of CreateBallotStyle.



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

def initialize(form)
  @form = form
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.



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

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

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

  create_ballot_style_questions!

  broadcast(:ok)
end