Class: Longleaf::ConfigurationValidator
- Inherits:
-
Object
- Object
- Longleaf::ConfigurationValidator
- Defined in:
- lib/longleaf/services/configuration_validator.rb
Overview
Abstract configuration validator class
Direct Known Subclasses
ApplicationConfigValidator, MetadataValidator, ServiceDefinitionValidator, ServiceMappingValidator, StorageLocationValidator
Instance Attribute Summary collapse
-
#result ⇒ Object
readonly
Returns the value of attribute result.
Instance Method Summary collapse
-
#assert(fail_message, assertion_passed) ⇒ Object
Asserts that the given conditional is true, raising a ConfigurationError if it is not.
-
#fail(fail_message) ⇒ Object
Indicate that validation has failed, throwing a Configuration error with the given message.
-
#initialize(config) ⇒ ConfigurationValidator
constructor
A new instance of ConfigurationValidator.
-
#register_error(error) ⇒ Object
Registers an error to the result for this validator.
-
#register_on_failure ⇒ Object
Performs the provided block.
-
#validate_config ⇒ ConfigurationValidationResult
Verify that the provided configuration is valid.
Constructor Details
#initialize(config) ⇒ ConfigurationValidator
Returns a new instance of ConfigurationValidator.
6 7 8 9 |
# File 'lib/longleaf/services/configuration_validator.rb', line 6 def initialize(config) @result = ConfigurationValidationResult.new @config = config end |
Instance Attribute Details
#result ⇒ Object (readonly)
Returns the value of attribute result.
4 5 6 |
# File 'lib/longleaf/services/configuration_validator.rb', line 4 def result @result end |
Instance Method Details
#assert(fail_message, assertion_passed) ⇒ Object
Asserts that the given conditional is true, raising a ConfigurationError if it is not.
20 21 22 |
# File 'lib/longleaf/services/configuration_validator.rb', line 20 def assert(, assertion_passed) fail() unless assertion_passed end |
#fail(fail_message) ⇒ Object
Indicate that validation has failed, throwing a Configuration error with the given message
25 26 27 |
# File 'lib/longleaf/services/configuration_validator.rb', line 25 def fail() raise ConfigurationError.new() end |
#register_error(error) ⇒ Object
Registers an error to the result for this validator
30 31 32 33 34 35 36 |
# 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 ⇒ Object
Performs the provided block. If the block produces a ConfigurationError, the error is swallowed and registered to the result
40 41 42 43 44 45 46 |
# File 'lib/longleaf/services/configuration_validator.rb', line 40 def register_on_failure begin yield rescue ConfigurationError => err register_error(err.) end end |
#validate_config ⇒ ConfigurationValidationResult
Verify that the provided configuration is valid
13 14 15 16 17 |
# File 'lib/longleaf/services/configuration_validator.rb', line 13 def validate_config register_on_failure { validate } @result end |