Class: Longleaf::ServiceMappingValidator

Inherits:
ConfigurationValidator show all
Defined in:
lib/longleaf/services/service_mapping_validator.rb

Overview

Validates application configuration of service to location mappings

Class Method Summary collapse

Class Method Details

.validate_config(config) ⇒ Object

Validates service mapping configuration to ensure that it is syntactically and referentially correct.

Parameters:

  • config (Hash)

    hash containing the application configuration



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/longleaf/services/service_mapping_validator.rb', line 14

def self.validate_config(config)
  assert("Configuration must be a hash, but a #{config.class} was provided", config.class == Hash)
  assert("Configuration must contain a root '#{AF::SERVICE_MAPPINGS}' key", config.key?(AF::SERVICE_MAPPINGS))
  mappings = config[AF::SERVICE_MAPPINGS]
  return if mappings.nil? || mappings.empty?
  assert("'#{AF::SERVICE_MAPPINGS}' must be an array of mappings", mappings.is_a?(Array))

  service_names = config[AF::SERVICES].keys
  location_names = config[AF::LOCATIONS].keys

  mappings.each do |mapping|
    assert("Mapping must be a hash, but received #{mapping.inspect} instead", mapping.is_a?(Hash))

    validate_mapping_field(AF::LOCATIONS, mapping, location_names)
    validate_mapping_field(AF::SERVICES, mapping, service_names)
  end
end