Class: Decidim::Budgets::Admin::CreateBudget

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

Overview

This command is executed when the user creates an Budget from the admin panel.

Instance Method Summary collapse

Methods inherited from Command

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

Constructor Details

#initialize(form) ⇒ CreateBudget

Returns a new instance of CreateBudget.



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

def initialize(form)
  @form = form
end

Dynamic Method Handling

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

Instance Method Details

#callObject

Creates the budget if valid.

Broadcasts :ok if successful, :invalid otherwise.



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

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

  create_budget!

  broadcast(:ok, budget)
end