Class: Decidim::Budgets::Admin::UpdateBudget

Inherits:
Command
  • Object
show all
Defined in:
decidim-budgets/app/commands/decidim/budgets/admin/update_budget.rb

Overview

This command is executed when the user updates a Budget from the admin panel.

Instance Method Summary collapse

Methods inherited from Command

call, #evaluate, #method_missing, #respond_to_missing?, #transaction

Constructor Details

#initialize(form, budget) ⇒ UpdateBudget

Returns a new instance of UpdateBudget.


9
10
11
12
# File 'decidim-budgets/app/commands/decidim/budgets/admin/update_budget.rb', line 9

def initialize(form, budget)
  @form = form
  @budget = budget
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Decidim::Command

Instance Method Details

#callObject

Updates the budget if valid.

Broadcasts :ok if successful, :invalid otherwise.


17
18
19
20
21
22
23
# File 'decidim-budgets/app/commands/decidim/budgets/admin/update_budget.rb', line 17

def call
  return broadcast(:invalid) if form.invalid?

  update_budget!

  broadcast(:ok, budget)
end