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) ⇒ Pack

Returns a new instance of Pack.



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

def initialize(dir)
  @dir = dir
end

Instance Attribute Details

#dirObject (readonly)

Returns the value of attribute dir.



31
32
33
# File 'lib/judges/pack.rb', line 31

def dir
  @dir
end

Instance Method Details

#run(fbase, env) ⇒ Object

Run it with the given Factbase and environment variables.



38
39
40
41
42
43
44
45
46
47
48
# File 'lib/judges/pack.rb', line 38

def run(fbase, env)
  $fb = fbase
  env.each do |k, v|
    # rubocop:disable Security/Eval
    eval("$#{k} = '#{v}'", binding, __FILE__, __LINE__) # $foo = 42
    # rubocop:enable Security/Eval
  end
  s = File.join(@dir, script)
  raise "Can't load '#{s}'" unless File.exist?(s)
  load s
end

#scriptObject

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



51
52
53
# File 'lib/judges/pack.rb', line 51

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

#testsObject

Iterate over .yml tests.



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

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