Class: Decidim::CreateReport
- Defined in:
- app/commands/decidim/create_report.rb
Overview
A command with all the business logic when a user creates a report.
Instance Method Summary collapse
-
#call ⇒ Object
Executes the command.
-
#initialize(form, reportable) ⇒ CreateReport
constructor
Public: Initializes the command.
Methods inherited from Command
call, #evaluate, #method_missing, #respond_to_missing?, #transaction, #with_events
Constructor Details
#initialize(form, reportable) ⇒ CreateReport
Public: Initializes the command.
form - A form object with the params. reportable - The resource being reported
12 13 14 15 16 |
# File 'app/commands/decidim/create_report.rb', line 12 def initialize(form, reportable) @form = form @reportable = reportable @tool = Decidim::ModerationTools.new(reportable, current_user) 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, together with the report.
-
:invalid if the form was not valid and we could not proceed.
Returns nothing.
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'app/commands/decidim/create_report.rb', line 25 def call return broadcast(:invalid) if form.invalid? transaction do update_reported_content! create_report! update_report_count! end send_report_notification_to_moderators if hideable? hide! send_hide_notification_to_moderators end broadcast(:ok, report) end |