Class: Decidim::Elections::Admin::CreateQuestion

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

Overview

This command is executed when the user creates a Question from the admin panel.

Instance Method Summary collapse

Methods inherited from Command

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

Constructor Details

#initialize(form) ⇒ CreateQuestion

Returns a new instance of CreateQuestion.



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

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

Creates the question if valid.

Broadcasts :ok if successful, :invalid otherwise.



16
17
18
19
20
21
22
23
# File 'decidim-elections/app/commands/decidim/elections/admin/create_question.rb', line 16

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

  create_question!

  broadcast(:ok, question)
end