Class: Zold::TreeWallets
- Inherits:
-
Object
- Object
- Zold::TreeWallets
- Defined in:
- lib/zold/tree_wallets.rb
Overview
Collection of local wallets, in a tree of directories
Instance Method Summary collapse
-
#all ⇒ Object
Returns the list of their IDs (as plain text).
- #find(id) {|Zold::Wallet.new(File.join(path, (id.to_s.split('', 5).take(4) + [id.to_s]).join('/')))| ... } ⇒ Object
-
#initialize(dir) ⇒ TreeWallets
constructor
A new instance of TreeWallets.
- #path ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(dir) ⇒ TreeWallets
Returns a new instance of TreeWallets.
33 34 35 |
# File 'lib/zold/tree_wallets.rb', line 33 def initialize(dir) @dir = dir end |
Instance Method Details
#all ⇒ Object
Returns the list of their IDs (as plain text)
47 48 49 50 51 52 53 54 55 |
# File 'lib/zold/tree_wallets.rb', line 47 def all Dir.glob("#{path}/**/*#{Wallet::EXTENSION}").select do |f| basename = File.basename(f, Wallet::EXTENSION) File.file?(f) && !File.directory?(f) && basename =~ /^[0-9a-fA-F]{16}$/ && Id.new(basename).to_s == basename end.map { |w| Id.new(File.basename(w, Wallet::EXTENSION)) } end |
#find(id) {|Zold::Wallet.new(File.join(path, (id.to_s.split('', 5).take(4) + [id.to_s]).join('/')))| ... } ⇒ Object
57 58 59 60 61 |
# File 'lib/zold/tree_wallets.rb', line 57 def find(id) raise 'Id can\'t be nil' if id.nil? raise 'Id must be of type Id' unless id.is_a?(Id) yield Zold::Wallet.new(File.join(path, (id.to_s.split('', 5).take(4) + [id.to_s]).join('/'))) end |
#path ⇒ Object
41 42 43 44 |
# File 'lib/zold/tree_wallets.rb', line 41 def path FileUtils.mkdir_p(@dir) File.(@dir) end |
#to_s ⇒ Object
37 38 39 |
# File 'lib/zold/tree_wallets.rb', line 37 def to_s path end |