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.



41
42
43
44
45
# File 'lib/zold/commands/clean.rb', line 41

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

Instance Method Details

#clean(cps, _) ⇒ Object



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

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]}/#{File.size(c[:path])}b")
  end
end

#run(args = []) ⇒ Object



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

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 = @wallets.all if mine.empty?
  mine.map { |i| Id.new(i) }.each do |id|
    clean(Copies.new(File.join(@copies, id), log: @log), opts)
  end
end