Class: CARPS::YamlConfig

Inherits:
Object
  • Object
show all
Defined in:
lib/carps/util/config.rb

Overview

Configuration files that read yaml

Direct Known Subclasses

SystemConfig, UserConfig

Instance Method Summary collapse

Instance Method Details

#fail_hard(fatal) ⇒ Object

Should we fail hard, quiting the program?



30
31
32
# File 'lib/carps/util/config.rb', line 30

def fail_hard fatal
   @fatal = fatal
end

#read(filepath) ⇒ Object

Read a resource using the subclass’ parse_yaml.

Then load this resource using the subclass’ load_resource



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/carps/util/config.rb', line 37

def read filepath
   filepath = $CONFIG + filepath
   contents = ""
   result = nil
   # Try to read the  file
   begin
      contents = File.read filepath
   rescue
      # On failure, write a message to stderr and exit
      err "Could not read configuration file: " + filepath 
   end

   # Try to parse the file
   begin
      conf = YAML.load contents
      result = parse_yaml conf
   rescue
      err "Error parsing #{filepath}:\n#{$!}"
   end

   if result
      load_resources *result
   end
end