Class: Decidim::Surveys::Admin::PublishSurvey
- Inherits:
-
Command
- Object
- Command
- Decidim::Surveys::Admin::PublishSurvey
- Defined in:
- 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.
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 '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 |
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 '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 |