Class: Zold::CachedWallets

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

Overview

Collection of local wallets

Instance Method Summary collapse

Constructor Details

#initialize(wallets) ⇒ CachedWallets

Returns a new instance of CachedWallets.



33
34
35
36
37
# File 'lib/zold/cached_wallets.rb', line 33

def initialize(wallets)
  @wallets = wallets
  @cache = {}
  @mutex = Mutex.new
end

Instance Method Details

#allObject



47
48
49
# File 'lib/zold/cached_wallets.rb', line 47

def all
  @wallets.all
end

#find(id) ⇒ Object



51
52
53
54
55
56
57
58
59
60
# File 'lib/zold/cached_wallets.rb', line 51

def find(id)
  @wallets.find(id) do |wallet|
    yield(
      @mutex.synchronize do
        @cache[id] = wallet unless @cache[id]
        @cache[id]
      end
    )
  end
end

#pathObject



43
44
45
# File 'lib/zold/cached_wallets.rb', line 43

def path
  @wallets.path
end

#to_sObject



39
40
41
# File 'lib/zold/cached_wallets.rb', line 39

def to_s
  @wallets.to_s
end