Class: Judges::Judge
Overview
A single judge.
- Author
-
Yegor Bugayenko ([email protected])
- Copyright
-
Copyright © 2024 Yegor Bugayenko
- License
-
MIT
Defined Under Namespace
Classes: FakeValve
Instance Attribute Summary collapse
-
#dir ⇒ Object
readonly
Returns the value of attribute dir.
Instance Method Summary collapse
-
#initialize(dir, lib, loog) ⇒ Judge
constructor
A new instance of Judge.
-
#name ⇒ Object
Get the name of the judge.
-
#run(fbase, global, local, options) ⇒ Object
Run it with the given Factbase and environment variables.
-
#script ⇒ Object
Get the name of the .rb script in the judge.
-
#tests ⇒ Object
Return all .yml tests files.
Constructor Details
#initialize(dir, lib, loog) ⇒ Judge
Returns a new instance of Judge.
34 35 36 37 38 |
# File 'lib/judges/judge.rb', line 34 def initialize(dir, lib, loog) @dir = dir @lib = lib @loog = loog end |
Instance Attribute Details
#dir ⇒ Object (readonly)
Returns the value of attribute dir.
32 33 34 |
# File 'lib/judges/judge.rb', line 32 def dir @dir end |
Instance Method Details
#name ⇒ Object
Get the name of the judge.
67 68 69 |
# File 'lib/judges/judge.rb', line 67 def name File.basename(@dir) end |
#run(fbase, global, local, options) ⇒ Object
Run it with the given Factbase and environment variables.
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/judges/judge.rb', line 41 def run(fbase, global, local, ) $fb = fbase $judge = File.basename(@dir) $options = $loog = @loog $global = global $local = local $valve = FakeValve.new unless defined?($valve) .to_h.each { |k, v| ENV.store(k.to_s, v.to_s) } unless @lib.nil? raise "Lib dir #{@lib.to_rel} is absent" unless File.exist?(@lib) raise "Lib #{@lib.to_rel} is not a directory" unless File.directory?(@lib) Dir.glob(File.join(@lib, '*.rb')).each do |f| require_relative(File.absolute_path(f)) end end s = File.join(@dir, script) raise "Can't load '#{s}'" unless File.exist?(s) elapsed(@loog) do load(s, true) ensure $fb = $judge = $options = $loog = nil end end |
#script ⇒ Object
Get the name of the .rb script in the judge.
72 73 74 75 76 |
# File 'lib/judges/judge.rb', line 72 def script s = Dir.glob(File.join(@dir, '*.rb')).first raise "No *.rb scripts in #{@dir.to_rel}" if s.nil? File.basename(s) end |
#tests ⇒ Object
Return all .yml tests files.
79 80 81 |
# File 'lib/judges/judge.rb', line 79 def tests Dir.glob(File.join(@dir, '*.yml')) end |