Class: Judges::Pack
- Inherits:
-
Object
- Object
- Judges::Pack
- 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
-
#dir ⇒ Object
readonly
Returns the value of attribute dir.
Instance Method Summary collapse
-
#initialize(dir) ⇒ Pack
constructor
A new instance of Pack.
-
#run(fbase, env) ⇒ Object
Run it with the given Factbase and environment variables.
-
#script ⇒ Object
Get the name of the .rb script in the pack.
-
#tests ⇒ Object
Iterate over .yml tests.
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
#dir ⇒ Object (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 |
#script ⇒ Object
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 |
#tests ⇒ Object
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 |