class Rodolfo::JSONSchema
Rodolfo
Recipe JSON Schema
Public Class Methods
new(path, strict = false)
click to toggle source
# File lib/rodolfo/json_schema.rb, line 9 def initialize(path, strict = false) @path = path @strict = strict end
Public Instance Methods
json()
click to toggle source
# File lib/rodolfo/json_schema.rb, line 27 def json @json ||= File.read @path end
to_h()
click to toggle source
# File lib/rodolfo/json_schema.rb, line 23 def to_h JSON.parse json end
to_s()
click to toggle source
# File lib/rodolfo/json_schema.rb, line 31 def to_s json end
validate(data)
click to toggle source
Validate the json schema May raise a SchemaValidationError
# File lib/rodolfo/json_schema.rb, line 16 def validate(data) opts = { insert_defaults: true, strict: @strict } errors = JSON::Validator.fully_validate json, data, opts raise SchemaValidationError, errors unless errors.empty? data end