Class: Judges::Update
Overview
Update.
- Author
-
Yegor Bugayenko (yegor256@gmail.com)
- Copyright
-
Copyright © 2024 Yegor Bugayenko
- License
-
MIT
Instance Method Summary collapse
-
#initialize(loog) ⇒ Update
constructor
A new instance of Update.
- #run(opts, args) ⇒ Object
Constructor Details
#initialize(loog) ⇒ Update
Returns a new instance of Update.
38 39 40 |
# File 'lib/judges/commands/update.rb', line 38 def initialize(loog) @loog = loog end |
Instance Method Details
#run(opts, args) ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/judges/commands/update.rb', line 42 def run(opts, args) raise 'Exactly two arguments required' unless args.size == 2 dir = args[0] raise "The directory is absent: #{dir.to_rel}" unless File.exist?(dir) impex = Judges::Impex.new(@loog, args[1]) fb = impex.import(strict: false) fb = Factbase::Looged.new(fb, @loog) if opts['log'] before = fb.size = Judges::Options.new(opts['option']) @loog.debug("The following options provided:\n\t#{.to_s.gsub("\n", "\n\t")}") judges = Judges::Judges.new(dir, opts['lib'], @loog) c = 0 elapsed(@loog) do loop do c += 1 if c > 1 @loog.info("\n\nStarting cycle ##{c}#{opts['max-cycles'] ? " (out of #{opts['max-cycles']})" : ''}...") end churn = cycle(opts, judges, fb, ) impex.export(fb) if churn.zero? @loog.info("The update cycle ##{c} has made no changes to the factbase, let's stop") break end if !opts['max-cycles'].nil? && c >= opts['max-cycles'] @loog.info("Too many cycles already, as set by --max-cycles=#{opts['max-cycles']}, breaking") break end @loog.info("At the cycle #{c}, the factbase was modified by #{churn} fact(s)") end throw :"Update finished in #{c} cycle(s), #{format('+%d', fb.size - before)} fact(s)" end end |