Class: Decidim::Forms::AnswerQuestionnaire

Inherits:
Command
  • Object
show all
Includes:
MultipleAttachmentsMethods
Defined in:
app/commands/decidim/forms/answer_questionnaire.rb

Overview

This command is executed when the user answers a Questionnaire.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(form, questionnaire) ⇒ AnswerQuestionnaire

Initializes a AnswerQuestionnaire Command.

form - The form from which to get the data. questionnaire - The current instance of the questionnaire to be answered.



14
15
16
17
# File 'app/commands/decidim/forms/answer_questionnaire.rb', line 14

def initialize(form, questionnaire)
  @form = form
  @questionnaire = questionnaire
end

Instance Attribute Details

#formObject (readonly)

Returns the value of attribute form.



37
38
39
# File 'app/commands/decidim/forms/answer_questionnaire.rb', line 37

def form
  @form
end

#questionnaireObject (readonly)

Returns the value of attribute questionnaire.



37
38
39
# File 'app/commands/decidim/forms/answer_questionnaire.rb', line 37

def questionnaire
  @questionnaire
end

Instance Method Details

#callObject

Answers a questionnaire if it is valid

Broadcasts :ok if successful, :invalid otherwise.



22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'app/commands/decidim/forms/answer_questionnaire.rb', line 22

def call
  return broadcast(:invalid) if @form.invalid? || user_already_answered?

  with_events do
    answer_questionnaire
  end

  if @errors
    reset_form_attachments
    broadcast(:invalid)
  else
    broadcast(:ok)
  end
end