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.4.3 app/commands/decidim/budgets/checkout.rb
decidim-budgets-0.4.2 app/commands/decidim/budgets/checkout.rb
decidim-budgets-0.4.1 app/commands/decidim/budgets/checkout.rb
decidim-0.4.3 decidim-budgets/app/commands/decidim/budgets/checkout.rb
decidim-0.4.2 decidim-budgets/app/commands/decidim/budgets/checkout.rb
decidim-0.4.1 decidim-budgets/app/commands/decidim/budgets/checkout.rb
decidim-budgets-0.4.0 app/commands/decidim/budgets/checkout.rb
decidim-0.4.0 decidim-budgets/app/commands/decidim/budgets/checkout.rb
decidim-budgets-0.3.2 app/commands/decidim/budgets/checkout.rb
decidim-0.3.2 decidim-budgets/app/commands/decidim/budgets/checkout.rb
decidim-budgets-0.3.1 app/commands/decidim/budgets/checkout.rb
decidim-0.3.1 decidim-budgets/app/commands/decidim/budgets/checkout.rb
decidim-budgets-0.3.0 app/commands/decidim/budgets/checkout.rb
decidim-0.3.0 decidim-budgets/app/commands/decidim/budgets/checkout.rb
decidim-budgets-0.2.0 app/commands/decidim/budgets/checkout.rb
decidim-0.2.0 decidim-budgets/app/commands/decidim/budgets/checkout.rb