class Longleaf::ConfigurationValidator

Abstract configuration validator class

Attributes

result[R]

Public Class Methods

new(config) click to toggle source
# File lib/longleaf/services/configuration_validator.rb, line 6
def initialize(config)
  @result = ConfigurationValidationResult.new
  @config = config
end

Public Instance Methods

assert(fail_message, assertion_passed) click to toggle source

Asserts that the given conditional is true, raising a ConfigurationError if it is not.

# File lib/longleaf/services/configuration_validator.rb, line 20
def assert(fail_message, assertion_passed)
  fail(fail_message) unless assertion_passed
end
fail(fail_message) click to toggle source

Indicate that validation has failed, throwing a Configuration error with the given message

# File lib/longleaf/services/configuration_validator.rb, line 25
def fail(fail_message)
  raise ConfigurationError.new(fail_message)
end
register_error(error) click to toggle source

Registers an error to the result for this validator

# File lib/longleaf/services/configuration_validator.rb, line 30
def register_error(error)
  if error.is_a?(StandardError)
    @result.register_error(error.msg)
  else
    @result.register_error(error)
  end
end
register_on_failure() { || ... } click to toggle source

Performs the provided block. If the block produces a ConfigurationError, the error is swallowed and registered to the result

# File lib/longleaf/services/configuration_validator.rb, line 40
def register_on_failure
  begin
    yield
  rescue ConfigurationError => err
    register_error(err.message)
  end
end
validate_config() click to toggle source

Verify that the provided configuration is valid @return [ConfigurationValidationResult] the result of the validation

# File lib/longleaf/services/configuration_validator.rb, line 13
def validate_config
  register_on_failure { validate }

  @result
end