Class: Decidim::Surveys::Admin::PublishSurvey
- Defined in:
- decidim-surveys/app/commands/decidim/surveys/admin/publish_survey.rb
Overview
A command with all the business logic that publishes an existing survey.
Instance Method Summary collapse
-
#call ⇒ Object
Executes the command.
-
#initialize(survey, current_user) ⇒ PublishSurvey
constructor
Public: Initializes the command.
Methods inherited from Command
call, #evaluate, #method_missing, #respond_to_missing?, #transaction, #with_events
Constructor Details
#initialize(survey, current_user) ⇒ PublishSurvey
Public: Initializes the command.
survey - Decidim::Surveys::Survey current_user - the user performing the action
13 14 15 16 17 |
# File 'decidim-surveys/app/commands/decidim/surveys/admin/publish_survey.rb', line 13 def initialize(survey, current_user) @survey = survey @current_user = current_user @questionnaire = survey.questionnaire end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class Decidim::Command
Instance Method Details
#call ⇒ Object
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-surveys/app/commands/decidim/surveys/admin/publish_survey.rb', line 25 def call return broadcast(:invalid) if survey.published? transaction do publish_survey delete_responses if @survey.clean_after_publish? end broadcast(:ok, survey) end |