class AccountComponent::Commands::Withdraw

Public Class Methods

call(account_id:, amount:, withdrawal_id: nil, previous_message: nil) click to toggle source
# File lib/account_component/commands/withdraw.rb, line 12
def self.call(account_id:, amount:, withdrawal_id: nil, previous_message: nil)
  withdrawal_id ||= Identifier::UUID::Random.get
  instance = self.build
  instance.(withdrawal_id: withdrawal_id, account_id: account_id, amount: amount, previous_message: previous_message)
end
configure(receiver, attr_name: nil) click to toggle source
# File lib/account_component/commands/withdraw.rb, line 6
def self.configure(receiver, attr_name: nil)
  attr_name ||= :withdraw
  instance = build
  receiver.public_send("#{attr_name}=", instance)
end

Public Instance Methods

call(withdrawal_id:, account_id:, amount:, previous_message: nil) click to toggle source
# File lib/account_component/commands/withdraw.rb, line 18
def call(withdrawal_id:, account_id:, amount:, previous_message: nil)
  withdraw = self.class.build_message(Messages::Commands::Withdraw, previous_message)

  withdraw.withdrawal_id = withdrawal_id
  withdraw.account_id = account_id
  withdraw.amount = amount
  withdraw.time = clock.iso8601

  stream_name = command_stream_name(account_id)

  write.(withdraw, stream_name)

  withdraw
end