Class: AccountComponent::Commands::Deposit

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

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Command

#configure, included

Class Method Details

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



12
13
14
15
16
# File 'lib/account_component/commands/deposit.rb', line 12

def self.call(account_id:, amount:, deposit_id: nil, previous_message: nil)
  deposit_id ||= Identifier::UUID::Random.get
  instance = self.build
  instance.(deposit_id: deposit_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/deposit.rb', line 6

def self.configure(receiver, attr_name: nil)
  attr_name ||= :deposit
  instance = build
  receiver.public_send("#{attr_name}=", instance)
end

Instance Method Details

#call(deposit_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/deposit.rb', line 18

def call(deposit_id:, account_id:, amount:, previous_message: nil)
  deposit = self.class.build_message(Messages::Commands::Deposit, previous_message)

  deposit.deposit_id = deposit_id
  deposit. = 
  deposit.amount = amount
  deposit.time = clock.iso8601

  stream_name = command_stream_name()

  write.(deposit, stream_name)

  deposit
end