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.



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

def initialize(loog)
  @loog = loog
end

Instance Method Details

#run(opts, args) ⇒ Object



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

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)
  options = Judges::Options.new(opts['option'])
  @loog.debug("The following options provided:\n\t#{options.to_s.gsub("\n", "\n\t")}")
  errors = []
  done = Judges::Packs.new(dir, @loog).each_with_index do |p, i|
    @loog.info("Running #{p.dir.to_rel} (##{i})...")
    before = fb.size
    begin
      p.run(fb, options)
    rescue StandardError => e
      @loog.warn(Backtrace.new(e))
      errors << p.script
    end
    after = fb.size
    @loog.info("Pack #{p.dir.to_rel} added #{after - before} facts") if after > before
  end
  @loog.info("#{done} judges processed (#{errors.size} errors)")
  raise "Failed to update correctly (#{errors.size} errors)" unless errors.empty?
  impex.export(fb)
end