Class: SoarConfiguration::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/soar_configuration.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#errorsObject

Returns the value of attribute errors.



10
11
12
# File 'lib/soar_configuration.rb', line 10

def errors
  @errors
end

Instance Method Details

#load_from_configuration_service(environment) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/soar_configuration.rb', line 12

def load_from_configuration_service(environment)
  @errors = []
  context = ConfigurationService::Factory::EnvironmentContext.new(environment)
  configuration_service = ConfigurationService::Factory.create_client(context)
  result = configuration_service.request_configuration
  config = result.data
  $stderr.puts "Loaded configuration #{result.identifier}: #{result..inspect}"
  return config, @errors

rescue => e
  message = "Could not retrieve configuration from configuration service."
  @errors << 'invalid configuration service URI' if URI::InvalidURIError == e.class
  @errors << message
  @errors << e.message
  return nil, @errors
end

#load_from_yaml(filename) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/soar_configuration.rb', line 29

def load_from_yaml(filename)
  @errors = []
  config = YAML.load_file(filename)
  $stderr.puts "Loaded configuration #{filename}"
  
  if ((config == false) or (config.nil?))
    config = {}
    $stderr.puts "WARNING: Empty configuration! Set CFGSRV_IDENTIFIER to use the configuration service!"
  end
  return config, @errors

rescue => e
  message = "Could not load or parse configuration file. Is it YAML?"
  @errors << message
  @errors << e.message
  return nil, @errors
end

#validate(config) ⇒ Object



47
48
49
50
51
52
53
# File 'lib/soar_configuration.rb', line 47

def validate(config)
  @errors = []
  validator_class = config['validator']
  validator_class ||= 'SoarConfiguration::ConfigurationValidator'
  validator = Object::const_get(validator_class).new(config)
  @errors = validator.validate
end