Method: OpenC3::MetaConfigParser.load

Defined in:
lib/openc3/config/meta_config_parser.rb

.load(filename) ⇒ Object



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/openc3/config/meta_config_parser.rb', line 41

def self.load(filename)
  data = nil
  if File.exist?(filename)
    path = filename
    @basedir = File.dirname(filename)
  else
    path = File.join(@basedir, filename)
  end
  tf = Tempfile.new("temp.yaml")

  output = nil
  OpenC3.set_working_dir(File.dirname(path)) do
    output = ERB.new(File.read(path), trim_mode: "-").result(binding)
  end
  tf.write(output)
  tf.close
  begin
    data = Psych.safe_load(File.read(tf.path), aliases: true)
  rescue => error
    error_file = "#{filename}.err"
    File.open(error_file, 'w') { |file| file.puts output }
    raise error.exception("#{error.message}\n\nParsed output written to #{File.expand_path(error_file)}\n")
  end
  tf.unlink
  data
end