Class: AccountComponent::Commands::Withdraw

Inherits:
Object
  • Object
show all
Includes:
Command
Defined in:
lib/account_component/commands/withdraw.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Command

#configure, included

Class Method Details

.call(account_id:, amount:, withdrawal_id: nil, previous_message: nil) ⇒ Object



12
13
14
15
16
# 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: , amount: amount, previous_message: previous_message)
end

.configure(receiver, attr_name: nil) ⇒ Object



6
7
8
9
10
# 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

Instance Method Details

#call(withdrawal_id:, account_id:, amount:, previous_message: nil) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
31
# 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. = 
  withdraw.amount = amount
  withdraw.time = clock.iso8601

  stream_name = command_stream_name()

  write.(withdraw, stream_name)

  withdraw
end