Class: Zold::Clean

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

Overview

CLEAN command

Instance Method Summary collapse

Constructor Details

#initialize(wallets:, copies:, log: Log::Quiet.new) ⇒ Clean

Returns a new instance of Clean.



43
44
45
46
47
# File 'lib/zold/commands/clean.rb', line 43

def initialize(wallets:, copies:, log: Log::Quiet.new)
  @wallets = wallets
  @copies = copies
  @log = log
end

Instance Method Details

#clean(cps, _) ⇒ Object



61
62
63
64
65
66
67
68
69
# File 'lib/zold/commands/clean.rb', line 61

def clean(cps, _)
  deleted = cps.clean
  @log.debug("#{deleted} expired local copies removed for #{cps}, #{cps.all.count} left:")
  cps.all.each do |c|
    wallet = Wallet.new(c[:path])
    @log.debug("  #{c[:name]}: #{c[:score]} #{wallet.balance}/#{wallet.txns.count}t/\
#{wallet.digest[0, 6]}/#{Size.new(File.size(c[:path]))}/#{Age.new(File.mtime(c[:path]))}")
  end
end

#run(args = []) ⇒ Object



49
50
51
52
53
54
55
56
57
58
59
# File 'lib/zold/commands/clean.rb', line 49

def run(args = [])
  opts = Slop.parse(args, help: true, suppress_errors: true) do |o|
    o.banner = "Usage: zold clean [ID...] [options]
Available options:"
    o.bool '--help', 'Print instructions'
  end
  mine = Args.new(opts, @log).take || return
  (mine.empty? ? @wallets.all : mine.map { |i| Id.new(i) }).each do |id|
    clean(Copies.new(File.join(@copies, id), log: @log), opts)
  end
end