Class: Decidim::Templates::Admin::ApplyQuestionnaireTemplate

Inherits:
Command
  • Object
show all
Includes:
QuestionnaireCopier
Defined in:
decidim-templates/app/commands/decidim/templates/admin/apply_questionnaire_template.rb

Instance Method Summary collapse

Methods included from QuestionnaireCopier

#copy_question_display_conditions, #copy_questionnaire_answer_options, #copy_questionnaire_matrix_rows, #copy_questionnaire_questions, #find_answer_option_by_body, #find_question_by_position

Methods inherited from Command

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

Constructor Details

#initialize(questionnaire, template) ⇒ ApplyQuestionnaireTemplate

Public: Initializes the command.

template - The template we want to apply questionnaire - The questionnaire we want to use the template



14
15
16
17
# File 'decidim-templates/app/commands/decidim/templates/admin/apply_questionnaire_template.rb', line 14

def initialize(questionnaire, template)
  @questionnaire = questionnaire
  @template = template
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. Broadcasts these events:

  • :ok when everything is valid.

  • :invalid if the form was not valid and we could not proceed.

Returns nothing.



25
26
27
28
29
30
31
32
33
34
# File 'decidim-templates/app/commands/decidim/templates/admin/apply_questionnaire_template.rb', line 25

def call
  return broadcast(:invalid) unless @template && @template.valid?

  Template.transaction do
    apply_template
    copy_questionnaire_questions(@template.templatable, @questionnaire)
  end

  broadcast(:ok, @questionnaire)
end