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.



39
40
41
42
43
# File 'lib/zold/commands/clean.rb', line 39

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

Instance Method Details

#clean(cps, _) ⇒ Object



58
59
60
61
62
# File 'lib/zold/commands/clean.rb', line 58

def clean(cps, _)
  deleted = cps.clean
  @log.debug("#{deleted} expired local copies removed for #{cps}, \
#{cps.all.count} left")
end

#run(args = []) ⇒ Object



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

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