Sha256: 3b70fa6807f939621d144cd22b387562bd69fd3b18c5b9d36f330920934aa4d2

Contents?: true

Size: 896 Bytes

Versions: 24

Compression:

Stored size: 896 Bytes

Contents

# frozen_string_literal: true

module Decidim
  module Budgets
    # A command with all the business to checkout.
    class Checkout < Rectify::Command
      # Public: Initializes the command.
      #
      # order - The current order for the user.
      # component - The current component.
      def initialize(order, component)
        @order = order
        @component = component
      end

      # Executes the command. Broadcasts these events:
      #
      # - :ok when everything is valid.
      # - :invalid if the there is an error.
      #
      # Returns nothing.
      def call
        return broadcast(:invalid, @order) unless checkout!
        broadcast(:ok, @order)
      end

      private

      def checkout!
        return unless @order

        @order.with_lock do
          @order.checked_out_at = Time.current
          @order.save
        end
      end
    end
  end
end

Version data entries

24 entries across 24 versions & 1 rubygems

Version Path
decidim-budgets-0.18.1 app/commands/decidim/budgets/checkout.rb
decidim-budgets-0.17.2 app/commands/decidim/budgets/checkout.rb
decidim-budgets-0.18.0 app/commands/decidim/budgets/checkout.rb
decidim-budgets-0.17.1 app/commands/decidim/budgets/checkout.rb
decidim-budgets-0.16.1 app/commands/decidim/budgets/checkout.rb
decidim-budgets-0.17.0 app/commands/decidim/budgets/checkout.rb
decidim-budgets-0.16.0 app/commands/decidim/budgets/checkout.rb
decidim-budgets-0.15.2 app/commands/decidim/budgets/checkout.rb
decidim-budgets-0.15.1 app/commands/decidim/budgets/checkout.rb
decidim-budgets-0.15.0 app/commands/decidim/budgets/checkout.rb
decidim-budgets-0.14.4 app/commands/decidim/budgets/checkout.rb
decidim-budgets-0.14.3 app/commands/decidim/budgets/checkout.rb
decidim-budgets-0.14.2 app/commands/decidim/budgets/checkout.rb
decidim-budgets-0.14.1 app/commands/decidim/budgets/checkout.rb
decidim-budgets-0.13.1 app/commands/decidim/budgets/checkout.rb
decidim-budgets-0.12.2 app/commands/decidim/budgets/checkout.rb
decidim-budgets-0.13.0 app/commands/decidim/budgets/checkout.rb
decidim-budgets-0.12.1 app/commands/decidim/budgets/checkout.rb
decidim-budgets-0.13.0.pre1 app/commands/decidim/budgets/checkout.rb
decidim-budgets-0.12.0 app/commands/decidim/budgets/checkout.rb