Class: Decidim::Plans::DestroyPlan
- Inherits:
-
Rectify::Command
- Object
- Rectify::Command
- Decidim::Plans::DestroyPlan
- Defined in:
- app/commands/decidim/plans/destroy_plan.rb
Overview
A command with all the business logic when a user destroys a draft plan.
Instance Method Summary collapse
-
#call ⇒ Object
Executes the command.
-
#initialize(plan, current_user) ⇒ DestroyPlan
constructor
Public: Initializes the command.
Constructor Details
#initialize(plan, current_user) ⇒ DestroyPlan
Public: Initializes the command.
plan - The plan to destroy. current_user - The current user.
11 12 13 14 |
# File 'app/commands/decidim/plans/destroy_plan.rb', line 11 def initialize(plan, current_user) @plan = plan @current_user = current_user end |
Instance Method Details
#call ⇒ Object
Executes the command. Broadcasts these events:
-
:ok when everything is valid and the plan is deleted.
-
:invalid if the plan is not a draft.
-
:invalid if the plan’s author is not the current user.
Returns nothing.
23 24 25 26 27 28 29 30 |
# File 'app/commands/decidim/plans/destroy_plan.rb', line 23 def call return broadcast(:invalid) unless @plan.draft? return broadcast(:invalid) unless @plan.(@current_user) @plan.destroy! broadcast(:ok, @plan) end |