Class: ShinseiConfig::SchemaValidator
- Inherits:
-
Object
- Object
- ShinseiConfig::SchemaValidator
- Defined in:
- lib/shinsei_config/schema_validator.rb
Overview
Wraps dry-schema for validating configuration
Instance Attribute Summary collapse
-
#schema ⇒ Object
readonly
Returns the value of attribute schema.
Instance Method Summary collapse
-
#initialize ⇒ SchemaValidator
constructor
A new instance of SchemaValidator.
- #validate!(config_hash) ⇒ Object
Constructor Details
#initialize ⇒ SchemaValidator
Returns a new instance of SchemaValidator.
14 15 16 |
# File 'lib/shinsei_config/schema_validator.rb', line 14 def initialize(**, &) @schema = Dry::Schema.define(processor_type: Dry::Schema::JSON, **, &) end |
Instance Attribute Details
#schema ⇒ Object (readonly)
Returns the value of attribute schema.
11 12 13 |
# File 'lib/shinsei_config/schema_validator.rb', line 11 def schema @schema end |
Instance Method Details
#validate!(config_hash) ⇒ Object
19 20 21 22 23 24 25 |
# File 'lib/shinsei_config/schema_validator.rb', line 19 def validate!(config_hash) result = schema.call(config_hash) return if result.success? raise ValidationError, result.errors end |