Class: Decidim::Surveys::CreateSurvey

Inherits:
Command
  • Object
show all
Defined in:
decidim-surveys/app/commands/decidim/surveys/create_survey.rb

Overview

Command that gets called whenever a component’s survey has to be created. It usually happens as a callback when the component itself is created.

Instance Method Summary collapse

Methods inherited from Command

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

Constructor Details

#initialize(component) ⇒ CreateSurvey

Returns a new instance of CreateSurvey.



8
9
10
# File 'decidim-surveys/app/commands/decidim/surveys/create_survey.rb', line 8

def initialize(component)
  @component = component
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Decidim::Command

Instance Method Details

#callObject



12
13
14
15
16
# File 'decidim-surveys/app/commands/decidim/surveys/create_survey.rb', line 12

def call
  @survey = Survey.new(component: @component, questionnaire: Decidim::Forms::Questionnaire.new)

  @survey.save ? broadcast(:ok) : broadcast(:invalid)
end