Sha256: ac761456b8e61ba454b543e81d441b0452665793eaccb15b7d0f0102056cb41c

Contents?: true

Size: 886 Bytes

Versions: 56

Compression:

Stored size: 886 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.
      # feature - The current feature.
      def initialize(order, feature)
        @order = order
        @feature = feature
      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

56 entries across 56 versions & 2 rubygems

Version Path
decidim-budgets-0.10.1 app/commands/decidim/budgets/checkout.rb
decidim-budgets-0.10.0 app/commands/decidim/budgets/checkout.rb
decidim-budgets-0.9.3 app/commands/decidim/budgets/checkout.rb
decidim-budgets-0.9.2 app/commands/decidim/budgets/checkout.rb
decidim-budgets-0.9.1 app/commands/decidim/budgets/checkout.rb
decidim-budgets-0.9.0 app/commands/decidim/budgets/checkout.rb
decidim-budgets-0.8.4 app/commands/decidim/budgets/checkout.rb
decidim-budgets-0.8.3 app/commands/decidim/budgets/checkout.rb
decidim-budgets-0.8.2 app/commands/decidim/budgets/checkout.rb
decidim-budgets-0.8.1 app/commands/decidim/budgets/checkout.rb
decidim-budgets-0.8.0 app/commands/decidim/budgets/checkout.rb
decidim-budgets-0.7.4 app/commands/decidim/budgets/checkout.rb
decidim-budgets-0.7.3 app/commands/decidim/budgets/checkout.rb
decidim-budgets-0.7.2 app/commands/decidim/budgets/checkout.rb
decidim-budgets-0.7.1 app/commands/decidim/budgets/checkout.rb
decidim-budgets-0.7.0 app/commands/decidim/budgets/checkout.rb
decidim-budgets-0.6.8 app/commands/decidim/budgets/checkout.rb
decidim-0.6.8 decidim-budgets/app/commands/decidim/budgets/checkout.rb
decidim-budgets-0.6.7 app/commands/decidim/budgets/checkout.rb
decidim-0.6.7 decidim-budgets/app/commands/decidim/budgets/checkout.rb