Class: Rodolfo::JSONSchema
- Inherits:
-
Object
- Object
- Rodolfo::JSONSchema
- Defined in:
- lib/rodolfo/json_schema.rb
Overview
Rodolfo Recipe JSON Schema
Instance Method Summary collapse
-
#initialize(path) ⇒ JSONSchema
constructor
A new instance of JSONSchema.
- #json ⇒ Object
- #to_h ⇒ Object
- #to_s ⇒ Object
-
#validate(data) ⇒ Object
Validate the json schema May raise a SchemaValidationError.
Constructor Details
#initialize(path) ⇒ JSONSchema
Returns a new instance of JSONSchema.
9 10 11 |
# File 'lib/rodolfo/json_schema.rb', line 9 def initialize(path) @path = path end |
Instance Method Details
#json ⇒ Object
26 27 28 |
# File 'lib/rodolfo/json_schema.rb', line 26 def json @json ||= File.read @path end |
#to_h ⇒ Object
22 23 24 |
# File 'lib/rodolfo/json_schema.rb', line 22 def to_h JSON.parse json end |
#to_s ⇒ Object
30 31 32 |
# File 'lib/rodolfo/json_schema.rb', line 30 def to_s json end |
#validate(data) ⇒ Object
Validate the json schema May raise a SchemaValidationError
15 16 17 18 19 20 |
# File 'lib/rodolfo/json_schema.rb', line 15 def validate(data) opts = { insert_defaults: true, strict: true } errors = JSON::Validator.fully_validate json, data, opts raise SchemaValidationError, errors unless errors.empty? data end |