Class: Judges::Import
Overview
The import 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
-
#initialize(loog) ⇒ Import
constructor
Initialize.
-
#run(opts, args) ⇒ Object
Run the import command (called by the
bin/judgesscript).
Constructor Details
#initialize(loog) ⇒ Import
Initialize.
23 24 25 |
# File 'lib/judges/commands/import.rb', line 23 def initialize(loog) @loog = loog end |
Instance Method Details
#run(opts, args) ⇒ Object
Run the import command (called by the bin/judges script).
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/judges/commands/import.rb', line 31 def run(opts, args) raise 'Exactly two arguments required' unless args.size == 2 raise "File not found #{args[0].to_rel}" unless File.exist?(args[0]) elapsed(@loog, level: Logger::INFO) do yaml = YAML.load_file(args[0], permitted_classes: [Time]) @loog.info("YAML loaded from #{args[0].to_rel} (#{yaml.size} facts)") impex = Judges::Impex.new(@loog, args[1]) fb = impex.import(strict: false) if opts['log'] require 'factbase/logged' fb = Factbase::Logged.new(fb, @loog) end yaml.each do |i| f = fb.insert i.each do |p, v| f.send(:"#{p}=", v) end end impex.export(fb) throw :"👍 Import of #{yaml.size} facts completed" end end |