Module: DependencyManager::ConfigSchemaMacros
- Included in:
- Factory
- Defined in:
- lib/dependency_manager/config_schema_macros.rb
Overview
Class-level methods for validation of configurations
Defined Under Namespace
Modules: ClassMethods
Class Method Summary collapse
-
.included(klass) ⇒ void
Hook for binding class-level methods to the child class.
Instance Method Summary collapse
-
#validate(target: configuration) ⇒ Dry::Validation::Result
Runs validation against configuration without throwing errors.
-
#validate!(target: configuration) ⇒ TrueClass
Immediate return validation that will raise an exception if the contract is not fulfilled.
Class Method Details
.included(klass) ⇒ void
This method returns an undefined value.
Hook for binding class-level methods to the child class
12 13 14 |
# File 'lib/dependency_manager/config_schema_macros.rb', line 12 def self.included(klass) klass.extend(ClassMethods) end |
Instance Method Details
#validate(target: configuration) ⇒ Dry::Validation::Result
Runs validation against configuration without throwing errors
22 23 24 |
# File 'lib/dependency_manager/config_schema_macros.rb', line 22 def validate(target: configuration) self.class.validate(**target) end |
#validate!(target: configuration) ⇒ TrueClass
Immediate return validation that will raise an exception if the contract is not fulfilled
37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/dependency_manager/config_schema_macros.rb', line 37 def validate!(target: configuration) validation_result = validate(target: target) return true if validation_result.success? errors = validation_result .errors .map { |e| "#{e.path} #{e.text}" } .join(', ') raise ArgumentError, "Configuration is invalid: #{errors}" end |