Class: Judges::Trim
Overview
Trim.
- Author
-
Yegor Bugayenko (yegor256@gmail.com)
- Copyright
-
Copyright © 2024 Yegor Bugayenko
- License
-
MIT
Instance Method Summary collapse
-
#initialize(loog) ⇒ Trim
constructor
A new instance of Trim.
- #run(opts, args) ⇒ Object
Constructor Details
#initialize(loog) ⇒ Trim
Returns a new instance of Trim.
33 34 35 |
# File 'lib/judges/commands/trim.rb', line 33 def initialize(loog) @loog = loog end |
Instance Method Details
#run(opts, args) ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/judges/commands/trim.rb', line 37 def run(opts, args) raise 'Exactly one argument required' unless args.size == 1 impex = Judges::Impex.new(@loog, args[0]) fb = impex.import query = opts['query'] if query.nil? days = opts['days'] day = Time.now - (days * 60 * 60 * 24) query = "(lt time #{day.utc.iso8601})" @loog.info("Deleting facts that are older than #{days} days") else raise 'Specify either --days or --query' unless opts['days'].nil? end elapsed(@loog) do deleted = fb.query(query).delete! throw :'No facts deleted' if deleted.zero? impex.export(fb) throw :"🗑 #{deleted} fact(s) deleted" end end |