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 (yegor256@gmail.com)
- Copyright
-
Copyright © 2024-2025 Yegor Bugayenko
- License
-
MIT
Instance Method Summary collapse
-
#initialize(loog) ⇒ Import
constructor
A new instance of Import.
- #run(opts, args) ⇒ Object
Constructor Details
#initialize(loog) ⇒ Import
Returns a new instance of Import.
21 22 23 |
# File 'lib/judges/commands/import.rb', line 21 def initialize(loog) @loog = loog end |
Instance Method Details
#run(opts, args) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/judges/commands/import.rb', line 25 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 finished" end end |