Class: Judges::Update

Inherits:
Object
  • 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.



33
34
35
# File 'lib/judges/commands/update.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
57
# File 'lib/judges/commands/update.rb', line 37

def run(_opts, args)
  raise 'Exactly two arguments required' unless args.size == 2
  dir = args[0]
  raise "The directory is absent: #{dir}" unless File.exist?(dir)
  file = args[1]
  fb = Factbase.new
  if File.exist?(file)
    fb.import(File.read(file))
    @loog.info("Factbase imported from #{file} (#{File.size(file)} bytes)")
  else
    @loog.info("There is no Factbase to import from #{file}")
  end
  done = Judges::Packs.new(dir).each_with_index do |p, i|
    @loog.info("Pack ##{i} found in #{p.dir}")
    p.run(fb, {})
  end
  @loog.info("#{done} judges processed")
  FileUtils.mkdir_p(File.dirname(file))
  File.write(file, fb.export)
  @loog.info("Factbase exported to #{file} (#{File.size(file)} bytes)")
end