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

Inherits:
Command
  • Object
show all
Defined in:
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

Constructor Details

#initialize(form) ⇒ CreateBallotStyle

Returns a new instance of CreateBallotStyle.



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

def initialize(form)
  @form = form
end

Instance Method Details

#callObject

Executes the command. Broadcast this events:

  • :ok when everything is valid

  • :invalid when the form wasn’t valid and couldn’t proceed

Returns nothing.



17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File '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