Class: Philiprehberger::JsonSchema::CompiledSchema
- Inherits:
-
Object
- Object
- Philiprehberger::JsonSchema::CompiledSchema
- Defined in:
- lib/philiprehberger/json_schema/validator.rb
Overview
Compiled schema for repeated validation without re-parsing
Instance Method Summary collapse
-
#initialize(schema) ⇒ CompiledSchema
constructor
A new instance of CompiledSchema.
-
#valid?(data) ⇒ Boolean
Check if data is valid against the compiled schema.
-
#validate(data) ⇒ Array<String>
Validate data against the compiled schema.
Constructor Details
#initialize(schema) ⇒ CompiledSchema
Returns a new instance of CompiledSchema.
374 375 376 377 |
# File 'lib/philiprehberger/json_schema/validator.rb', line 374 def initialize(schema) @schema = schema @validator = Validator.new end |
Instance Method Details
#valid?(data) ⇒ Boolean
Check if data is valid against the compiled schema
391 392 393 |
# File 'lib/philiprehberger/json_schema/validator.rb', line 391 def valid?(data) validate(data).empty? end |
#validate(data) ⇒ Array<String>
Validate data against the compiled schema
383 384 385 |
# File 'lib/philiprehberger/json_schema/validator.rb', line 383 def validate(data) @validator.validate(data, @schema) end |