Class: Decidim::Plans::UpdatePlan
- Inherits:
-
Rectify::Command
- Object
- Rectify::Command
- Decidim::Plans::UpdatePlan
- Includes:
- AttachmentMethods, NestedUpdater
- Defined in:
- app/commands/decidim/plans/update_plan.rb
Overview
A command with all the business logic when a user updates a plan.
Instance Method Summary collapse
-
#call ⇒ Object
Executes the command.
-
#initialize(form, current_user, plan) ⇒ UpdatePlan
constructor
Public: Initializes the command.
Constructor Details
#initialize(form, current_user, plan) ⇒ UpdatePlan
Public: Initializes the command.
form - A form object with the params. current_user - The current user. plan - the plan to update.
15 16 17 18 19 20 |
# File 'app/commands/decidim/plans/update_plan.rb', line 15 def initialize(form, current_user, plan) @form = form @current_user = current_user @plan = plan @attached_to = plan end |
Instance Method Details
#call ⇒ Object
Executes the command. Broadcasts these events:
-
:ok when everything is valid, together with the plan.
-
:invalid if the form wasn’t valid and we couldn’t proceed.
Returns nothing.
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'app/commands/decidim/plans/update_plan.rb', line 28 def call return broadcast(:invalid) unless plan.editable_by?(current_user) if return broadcast(:invalid) if end if form.invalid? return broadcast(:invalid) end Decidim::Plans.tracer.trace!(@current_user) do transaction do update_plan update_plan_contents if end end broadcast(:ok, plan) end |