Class: Zold::JournaledPipeline::Wallets

Inherits:
SimpleDelegator
  • Object
show all
Defined in:
lib/zold/node/journaled_pipeline.rb

Overview

Decorated wallets

Instance Method Summary collapse

Constructor Details

#initialize(wallets, log) ⇒ Wallets

Returns a new instance of Wallets.



39
40
41
42
43
# File 'lib/zold/node/journaled_pipeline.rb', line 39

def initialize(wallets, log)
  @wallets = wallets
  @log = log
  super(wallets)
end

Instance Method Details

#acq(id, exclusive: false) ⇒ Object



45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/zold/node/journaled_pipeline.rb', line 45

def acq(id, exclusive: false)
  @wallets.acq(id, exclusive: exclusive) do |wallet|
    return yield wallet unless exclusive
    before = wallet.exists? ? IO.read(wallet.path) : ''
    res = yield wallet
    after = wallet.exists? ? IO.read(wallet.path) : ''
    unless before == after
      diff = Diffy::Diff.new(before, after, context: 0).to_s
      @log.info("The wallet #{id} was modified:\n  #{diff.gsub("\n", "\n  ")}")
    end
    res
  end
end