Class: Judges::Pack

Inherits:
Object
  • Object
show all
Defined in:
lib/judges/pack.rb

Overview

A single pack.

Author

Yegor Bugayenko (yegor256@gmail.com)

Copyright

Copyright © 2024 Yegor Bugayenko

License

MIT

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(dir, loog) ⇒ Pack

Returns a new instance of Pack.



35
36
37
38
# File 'lib/judges/pack.rb', line 35

def initialize(dir, loog)
  @dir = dir
  @loog = loog
end

Instance Attribute Details

#dirObject (readonly)

Returns the value of attribute dir.



33
34
35
# File 'lib/judges/pack.rb', line 33

def dir
  @dir
end

Instance Method Details

#run(fbase, options) ⇒ Object

Run it with the given Factbase and environment variables.



41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/judges/pack.rb', line 41

def run(fbase, options)
  $fb = fbase
  $judge = File.basename(@dir)
  $options = options
  $loog = @loog
  s = File.join(@dir, script)
  raise "Can't load '#{s}'" unless File.exist?(s)
  begin
    load s
  ensure
    $fb = $judge = $options = $loog = nil
  end
end

#scriptObject

Get the name of the .rb script in the pack.



56
57
58
# File 'lib/judges/pack.rb', line 56

def script
  File.basename(Dir.glob(File.join(@dir, '*.rb')).first)
end

#testsObject

Iterate over .yml tests.



61
62
63
64
65
# File 'lib/judges/pack.rb', line 61

def tests
  Dir.glob(File.join(@dir, '*.yml')).map do |f|
    YAML.load_file(f, permitted_classes: [Time])
  end
end