class Zold::Wallets
Collection of local wallets
Public Class Methods
new(dir)
click to toggle source
# File lib/zold/wallets.rb, line 37 def initialize(dir) @dir = dir end
Public Instance Methods
acq(id, exclusive: false) { |wallet(join(path, id + EXT))| ... }
click to toggle source
# File lib/zold/wallets.rb, line 67 def acq(id, exclusive: false) raise 'The flag can\'t be nil' if exclusive.nil? raise 'Id can\'t be nil' if id.nil? raise "Id must be of type Id, #{id.class.name} instead" unless id.is_a?(Id) yield Wallet.new(File.join(path, id.to_s + Wallet::EXT)) end
all()
click to toggle source
Returns the list of their IDs (as plain text)
# File lib/zold/wallets.rb, line 56 def all DirItems.new(path).fetch(recursive: false).select do |f| file = File.join(@dir, f) basename = File.basename(f, Wallet::EXT) File.file?(file) && !File.directory?(file) && basename =~ /^[0-9a-fA-F]{16}$/ && Id.new(basename).to_s == basename end.map { |w| Id.new(File.basename(w, Wallet::EXT)) } end
count()
click to toggle source
# File lib/zold/wallets.rb, line 74 def count Zold::DirItems.new(@dir) .fetch(recursive: false) .select { |f| f.end_with?(Wallet::EXT) } .count end
path()
click to toggle source
# File lib/zold/wallets.rb, line 50 def path FileUtils.mkdir_p(@dir) File.expand_path(@dir) end
to_s()
click to toggle source
@todo #70:30min Let's make it smarter. Instead of returning
the full path let's substract the prefix from it if it's equal to the current directory in Dir.pwd.
# File lib/zold/wallets.rb, line 44 def to_s mine = Pathname.new(File.expand_path(@dir)) home = Pathname.new(File.expand_path(Dir.pwd)) mine.relative_path_from(home).to_s end