Class: Judges::Update

Inherits:
Object show all
Defined in:
lib/judges/commands/update.rb

Overview

Update.

Author

Yegor Bugayenko (yegor256@gmail.com)

Copyright

Copyright © 2024 Yegor Bugayenko

License

MIT

Instance Method Summary collapse

Constructor Details

#initialize(loog) ⇒ Update

Returns a new instance of Update.



36
37
38
# File 'lib/judges/commands/update.rb', line 36

def initialize(loog)
  @loog = loog
end

Instance Method Details

#run(opts, args) ⇒ Object



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/judges/commands/update.rb', line 40

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)
  options = Judges::Options.new(opts['option'])
  @loog.debug("The following options provided:\n\t#{options.to_s.gsub("\n", "\n\t")}")
  packs = Judges::Packs.new(dir, opts['lib'], @loog)
  c = 0
  loop do
    c += 1
    diff = cycle(opts, packs, fb, options)
    impex.export(fb)
    break if diff.zero?
    if !opts['max-cycles'].nil? && c >= opts['max-cycles']
      @loog.info('Too many cycles already, as set by --max-cycles, breaking')
      break
    end
    @loog.info("By #{diff} facts the factbase \
      #{diff.positive? ? 'increased' : 'decreased'} \
      its size at the cycle ##{c}")
  end
  @loog.info("Update finished in #{c} cycles")
end