Class: Decidim::EnhancedTextwork::Admin::PublishAnswers
- Inherits:
-
Rectify::Command
- Object
- Rectify::Command
- Decidim::EnhancedTextwork::Admin::PublishAnswers
- Defined in:
- app/commands/decidim/enhanced_textwork/admin/publish_answers.rb
Overview
A command with all the business logic to publish many answers at once.
Instance Method Summary collapse
-
#call ⇒ Object
Executes the command.
-
#initialize(component, user, paragraph_ids) ⇒ PublishAnswers
constructor
Public: Initializes the command.
Constructor Details
#initialize(component, user, paragraph_ids) ⇒ PublishAnswers
Public: Initializes the command.
component - The component that contains the answers. user - the Decidim::User that is publishing the answers. paragraph_ids - the identifiers of the paragraphs with the answers to be published.
13 14 15 16 17 |
# File 'app/commands/decidim/enhanced_textwork/admin/publish_answers.rb', line 13 def initialize(component, user, paragraph_ids) @component = component @user = user @paragraph_ids = paragraph_ids end |
Instance Method Details
#call ⇒ Object
Executes the command. Broadcasts these events:
-
:ok when everything is valid.
-
:invalid if there are not paragraphs to publish.
Returns nothing.
25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'app/commands/decidim/enhanced_textwork/admin/publish_answers.rb', line 25 def call return broadcast(:invalid) unless paragraphs.any? paragraphs.each do |paragraph| transaction do mark_paragraph_as_answered(paragraph) notify_paragraph_answer(paragraph) end end broadcast(:ok) end |