Class: Judges::Judge
Overview
A single judge.
- Author
-
Yegor Bugayenko ([email protected])
- Copyright
-
Copyright © 2024-2025 Yegor Bugayenko
- License
-
MIT
Instance Attribute Summary collapse
-
#dir ⇒ Object
readonly
Returns the value of attribute dir.
Instance Method Summary collapse
-
#initialize(dir, lib, loog, start: Time.now) ⇒ Judge
constructor
Ctor.
-
#name ⇒ Object
Get the name of the judge.
-
#run(fb, global, local, options) ⇒ Factbase::Churn
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, start: Time.now) ⇒ Judge
Ctor.
23 24 25 26 27 28 |
# File 'lib/judges/judge.rb', line 23 def initialize(dir, lib, loog, start: Time.now) @dir = dir @lib = lib @loog = loog @start = start end |
Instance Attribute Details
#dir ⇒ Object (readonly)
Returns the value of attribute dir.
17 18 19 |
# File 'lib/judges/judge.rb', line 17 def dir @dir end |
Instance Method Details
#name ⇒ Object
Get the name of the judge.
64 65 66 |
# File 'lib/judges/judge.rb', line 64 def name File.basename(@dir) end |
#run(fb, global, local, options) ⇒ Factbase::Churn
Run it with the given Factbase and environment variables.
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/judges/judge.rb', line 37 def run(fb, global, local, ) $fb = Factbase::Tallied.new(fb) $judge = File.basename(@dir) $options = $loog = @loog $global = global $local = local $start = @start .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, intro: "#{$judge} finished", level: Logger::INFO) do load(s, true) $fb.churn ensure $fb = $judge = $options = $loog = nil end end |
#script ⇒ Object
Get the name of the .rb script in the judge.
69 70 71 72 73 74 |
# File 'lib/judges/judge.rb', line 69 def script b = "#{File.basename(@dir)}.rb" files = Dir.glob(File.join(@dir, '*.rb')).map { |f| File.basename(f) } raise "No #{b} script in #{@dir.to_rel} among #{files}" unless files.include?(b) b end |
#tests ⇒ Object
Return all .yml tests files.
77 78 79 |
# File 'lib/judges/judge.rb', line 77 def tests Dir.glob(File.join(@dir, '*.yml')) end |