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 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.
39 40 41 |
# File 'lib/judges/commands/import.rb', line 39 def initialize(loog) @loog = loog end |
Instance Method Details
#run(_opts, args) ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/judges/commands/import.rb', line 43 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) fb = Factbase::Looged.new(fb, @loog) 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 |