Class: Schemurai::Validator
- Inherits:
-
Object
- Object
- Schemurai::Validator
- Defined in:
- lib/schemurai.rb,
sig/schemurai.rbs
Overview
A reusable compiled JSON Schema validator.
Create validators through Schemurai.compile or SchemaRegistry#compile. Validator instances contain mutable evaluation state and must not be used concurrently or shared between Ractors.
Instance Method Summary collapse
-
#backend ⇒ backend
The backend reported by the evaluator, either
:rubyor:vm. -
#initialize(evaluator) ⇒ Validator
constructor
Wraps an evaluator implementation.
-
#valid?(instance) ⇒ Boolean
Returns whether
instanceis valid without building a detailed error list. -
#validate(instance) ⇒ Result
Validates
instanceand returns a Result containing all reported errors.
Constructor Details
#initialize(evaluator) ⇒ Validator
Wraps an evaluator implementation.
Applications should normally create validators through Schemurai.compile or SchemaRegistry#compile.
176 177 178 |
# File 'lib/schemurai.rb', line 176 def initialize(evaluator) @evaluator = evaluator end |
Instance Method Details
#backend ⇒ backend
The backend reported by the evaluator, either :ruby or :vm.
181 182 183 |
# File 'lib/schemurai.rb', line 181 def backend @evaluator.backend end |
#valid?(instance) ⇒ Boolean
Returns whether instance is valid without building a detailed error list.
191 192 193 |
# File 'lib/schemurai.rb', line 191 def valid?(instance) @evaluator.valid?(instance) end |
#validate(instance) ⇒ Result
Validates instance and returns a Result containing all reported errors.
186 187 188 |
# File 'lib/schemurai.rb', line 186 def validate(instance) @evaluator.validate(instance) end |