Class: AccountComponent::Commands::Withdraw
- Inherits:
-
Object
- Object
- AccountComponent::Commands::Withdraw
- Includes:
- Command
- Defined in:
- lib/account_component/commands/withdraw.rb
Class Method Summary collapse
- .call(account_id:, amount:, withdrawal_id: nil, previous_message: nil) ⇒ Object
- .configure(receiver, attr_name: nil) ⇒ Object
Instance Method Summary collapse
Methods included from Command
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: account_id, amount: amount, 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.(Messages::Commands::Withdraw, ) 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 |