Class: Decidim::Budgets::CancelOrder

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

Overview

A command with all the business to cancel an order.

Instance Method Summary collapse

Constructor Details

#initialize(order) ⇒ CancelOrder

Public: Initializes the command.

order - The current order for the user.


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

def initialize(order)
  @order = order
end

Instance Method Details

#callObject

Executes the command. Broadcasts these events:

  • :ok when everything is valid.

  • :invalid if the there is an error.

Returns nothing.


20
21
22
23
24
25
# File 'decidim-budgets/app/commands/decidim/budgets/cancel_order.rb', line 20

def call
  return broadcast(:invalid) if invalid_order?

  cancel_order!
  broadcast(:ok, @order)
end