Class: Zold::Check

Inherits:
Object
  • Object
show all
Defined in:
lib/zold/commands/check.rb

Overview

Wallet checking command

Instance Method Summary collapse

Constructor Details

#initialize(wallet:, wallets:, log: Log::Quiet.new) ⇒ Check

Returns a new instance of Check.



32
33
34
35
36
# File 'lib/zold/commands/check.rb', line 32

def initialize(wallet:, wallets:, log: Log::Quiet.new)
  @wallet = wallet
  @wallets = wallets
  @log = log
end

Instance Method Details

#runObject



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/zold/commands/check.rb', line 38

def run
  @wallet.income do |t|
    bnf = Pull.new(
      wallet: @wallets.find(Id.new(t[:beneficiary])),
      log: @log
    ).run
    bnf.check(t[:id], t[:amount], @wallet.id)
  end
  balance = @wallet.balance
  if balance.negative? && !@wallet.root?
    raise "Negative balance of #{@wallet} is not allowed: #{balance}"
  end
  @log.info("The #{@wallet} is clean")
  true
end