Sha256: dd05e215161b8ae876fed143d972b2f62666a2502698c0cf413e2974109f5d01

Contents?: true

Size: 885 Bytes

Versions: 10

Compression:

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

10 entries across 10 versions & 2 rubygems

Version Path
decidim-budgets-0.1.0 app/commands/decidim/budgets/checkout.rb
decidim-0.1.0 decidim-budgets/app/commands/decidim/budgets/checkout.rb
decidim-budgets-0.0.8.1 app/commands/decidim/budgets/checkout.rb
decidim-0.0.8.1 decidim-budgets/app/commands/decidim/budgets/checkout.rb
decidim-budgets-0.0.7 app/commands/decidim/budgets/checkout.rb
decidim-0.0.7 decidim-budgets/app/commands/decidim/budgets/checkout.rb
decidim-budgets-0.0.6 app/commands/decidim/budgets/checkout.rb
decidim-0.0.6 decidim-budgets/app/commands/decidim/budgets/checkout.rb
decidim-budgets-0.0.5 app/commands/decidim/budgets/checkout.rb
decidim-0.0.5 decidim-budgets/app/commands/decidim/budgets/checkout.rb