Sha256: 21e157600ed945a77e5129f510035c773f488d949a1ee803017fadc6f8f9a47d
Contents?: true
Size: 1022 Bytes
Versions: 15
Compression:
Stored size: 1022 Bytes
Contents
require 'jschema' module Validator class JSchema < Base def initialize(files_to_validate) @files_to_validate = files_to_validate schema_data = File.read("#{File.dirname(__FILE__)}/schema.json") schema_json = JSON.parse(schema_data) @meta_schema = ::JSchema.build(schema_json) end def validate(schema) schema_to_test = JSON.parse(schema) result = @meta_schema.validate schema_to_test if !result || result.length == 0 success << schema_to_test['title'] || schema_to_test.keys[0] else errors << "Schema validation failed: #{schema_to_test['title']}\n#{result.join("\n")}" end end def use_for_validation(schema) schema_to_test = JSON.parse(schema) begin ::JSchema.build(schema_to_test) rescue errors << "Data validation failed: #{schema_to_test['title']}\n#{$!}" # puts $!.backtrace else success << schema_to_test['title'] || schema_to_test.keys[0] end end end end
Version data entries
15 entries across 15 versions & 1 rubygems