Class: Zold::CachedWallets
- Inherits:
-
Object
- Object
- Zold::CachedWallets
- Defined in:
- lib/zold/cached_wallets.rb
Overview
Collection of local wallets
Instance Method Summary collapse
- #all ⇒ Object
- #find(id) ⇒ Object
-
#initialize(wallets) ⇒ CachedWallets
constructor
A new instance of CachedWallets.
- #path ⇒ Object
- #to_s ⇒ Object
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
#all ⇒ Object
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 |
# File 'lib/zold/cached_wallets.rb', line 51 def find(id) @wallets.find(id) do |wallet| w = @mutex.synchronize do @cache[id] = wallet unless @cache[id] @cache[id] end yield w end end |
#path ⇒ Object
43 44 45 |
# File 'lib/zold/cached_wallets.rb', line 43 def path @wallets.path end |
#to_s ⇒ Object
39 40 41 |
# File 'lib/zold/cached_wallets.rb', line 39 def to_s @wallets.to_s end |