Class: Cosmos::MetaConfigParser

Inherits:
Object
  • Object
show all
Defined in:
lib/cosmos/config/meta_config_parser.rb

Overview

Reads YAML formatted files describing a configuration file

Class Method Summary collapse

Class Method Details

.dump(object, filename) ⇒ Object



51
52
53
54
55
# File 'lib/cosmos/config/meta_config_parser.rb', line 51

def self.dump(object, filename)
  File.open(filename, 'w') do |file|
    file.write Psych.dump(object)
  end
end

.load(filename) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/cosmos/config/meta_config_parser.rb', line 29

def self.load(filename)
  data = nil
  if File.exist?(filename)
    path = filename
  else
    path = Cosmos.data_path("config/#{filename}")
  end
  tf = Tempfile.new("temp.yaml")
  output = ERB.new(File.read(path)).result(binding)
  tf.write(output)
  tf.close
  begin
    data = Psych.load_file(tf.path)
  rescue => error
    error_file = "ERROR_#{filename}"
    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