Sha256: 279a1407712a055b45c0b9d7836ea0babacd55b3e9d8e4b9fbcd5a7d5df9ed82

Contents?: true

Size: 897 Bytes

Versions: 5

Compression:

Stored size: 897 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

5 entries across 5 versions & 1 rubygems

Version Path
decidim-budgets-0.21.0 app/commands/decidim/budgets/checkout.rb
decidim-budgets-0.20.1 app/commands/decidim/budgets/checkout.rb
decidim-budgets-0.20.0 app/commands/decidim/budgets/checkout.rb
decidim-budgets-0.19.1 app/commands/decidim/budgets/checkout.rb
decidim-budgets-0.19.0 app/commands/decidim/budgets/checkout.rb