Class: Judges::Eval

Inherits:
Object show all
Defined in:
lib/judges/commands/eval.rb

Overview

The eval command.

This class is instantiated by the bin/judge command line interface. You are not supposed to instantiate it yourself.

Author

Yegor Bugayenko ([email protected])

Copyright

Copyright © 2024-2025 Yegor Bugayenko

License

MIT

Instance Method Summary collapse

Constructor Details

#initialize(loog) ⇒ Eval

Initialize.

Parameters:

  • loog (Loog)

    Logging facility



21
22
23
# File 'lib/judges/commands/eval.rb', line 21

def initialize(loog)
  @loog = loog
end

Instance Method Details

#run(opts, args) ⇒ Object

Run the eval command (called by the bin/judges script).

Parameters:

  • opts (Hash)

    Command line options (start with ‘–’)

  • args (Array)

    List of command line arguments

Raises:

  • (RuntimeError)

    If not exactly two arguments provided



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/judges/commands/eval.rb', line 29

def run(opts, args)
  raise 'Exactly two arguments required' unless args.size == 2
  impex = Judges::Impex.new(@loog, args[0])
  elapsed(@loog, level: Logger::INFO) do
    $fb = impex.import(strict: false)
    if opts['log']
      require 'factbase/logged'
      $fb = Factbase::Logged.new($fb, @loog)
    end
    expr = args[1]
    # rubocop:disable Security/Eval
    eval(expr)
    # rubocop:enable Security/Eval
    impex.export($fb)
    throw :'👍 Evaluated successfully'
  end
end