Module: Philiprehberger::JsonSchema
- Defined in:
- lib/philiprehberger/json_schema.rb,
lib/philiprehberger/json_schema/version.rb,
lib/philiprehberger/json_schema/validator.rb
Defined Under Namespace
Classes: CompiledSchema, Error, Validator
Constant Summary collapse
- VERSION =
'0.4.0'
Class Method Summary collapse
-
.compile(schema) ⇒ CompiledSchema
Compile a schema for repeated validation.
-
.valid?(data, schema) ⇒ Boolean
Check if data is valid against a JSON Schema.
-
.validate(data, schema) ⇒ Array<String>
Validate data against a JSON Schema and return error messages.
-
.validate!(data, schema) ⇒ Object
Validate data against a JSON Schema; raise on failure.
Class Method Details
.compile(schema) ⇒ CompiledSchema
Compile a schema for repeated validation
45 46 47 |
# File 'lib/philiprehberger/json_schema.rb', line 45 def self.compile(schema) CompiledSchema.new(schema) end |
.valid?(data, schema) ⇒ Boolean
Check if data is valid against a JSON Schema
24 25 26 |
# File 'lib/philiprehberger/json_schema.rb', line 24 def self.valid?(data, schema) validate(data, schema).empty? end |
.validate(data, schema) ⇒ Array<String>
Validate data against a JSON Schema and return error messages
15 16 17 |
# File 'lib/philiprehberger/json_schema.rb', line 15 def self.validate(data, schema) Validator.new.validate(data, schema) end |
.validate!(data, schema) ⇒ Object
Validate data against a JSON Schema; raise on failure.
34 35 36 37 38 39 |
# File 'lib/philiprehberger/json_schema.rb', line 34 def self.validate!(data, schema) errors = validate(data, schema) raise Error, errors.join('; ') unless errors.empty? data end |