Class: Vcloud::Core::ConfigLoader

Inherits:
Object
  • Object
show all
Defined in:
lib/vcloud/core/config_loader.rb

Instance Method Summary collapse

Instance Method Details

#load_config(config_file, schema = nil) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/vcloud/core/config_loader.rb', line 5

def load_config(config_file, schema = nil)
  input_config = YAML::load(File.open(config_file))

  # There is no way in YAML or Ruby to symbolize keys in a hash
  json_string = JSON.generate(input_config)
  config = JSON.parse(json_string, :symbolize_names => true)

  if schema
    validation = Core::ConfigValidator.validate(:base, config, schema)
    unless validation.valid?
      validation.errors.each do |error|
        Vcloud::Core.logger.fatal(error)
      end
      raise("Supplied configuration does not match supplied schema")
    end
  end
  config
end