Class: Decidim::Budgets::Admin::UpdateProjectsBudget

Inherits:
Command
  • Object
show all
Includes:
TranslatableAttributes
Defined in:
app/commands/decidim/budgets/admin/update_projects_budget.rb

Instance Method Summary collapse

Constructor Details

#initialize(destination_budget, project_ids) ⇒ UpdateProjectsBudget

Public: Initializes the command.

destination_budget - the destination budget for which the projects should update to. project_ids - the project ids to update.



13
14
15
16
17
# File 'app/commands/decidim/budgets/admin/update_projects_budget.rb', line 13

def initialize(destination_budget, project_ids)
  @destination_budget = destination_budget
  @project_ids = project_ids
  @response = { selection_name: "", successful: [], errored: [], failed_ids: [] }
end

Instance Method Details

#callObject



19
20
21
22
23
24
25
26
# File 'app/commands/decidim/budgets/admin/update_projects_budget.rb', line 19

def call
  return broadcast(:invalid_project_ids) if @project_ids.blank?
  return broadcast(:invalid_project_ids) if @destination_budget.blank?

  update_projects_budget

  broadcast(:update_projects_budget, @response)
end