1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
|
module JSON
class Schema
class Validator
attr_accessor :attributes, :formats, :uri, :names
attr_reader :default_formats
def initialize()
@attributes = {}
@formats = {}
@default_formats = {}
@uri = nil
@names = []
@metaschema_name = ''
end
def extend_schema_definition(schema_uri)
validator = JSON::Validator.validator_for(schema_uri)
@attributes.merge!(validator.attributes)
end
def validate(current_schema, data, fragments, processor, options = {})
current_schema.schema.each do |attr_name,attribute|
if @attributes.has_key?(attr_name.to_s)
@attributes[attr_name.to_s].validate(current_schema, data, fragments, processor, self, options)
end
end
data
end
def metaschema
if File.exists?(File.expand_path('../../../../resources', __FILE__))
resources = File.expand_path('../../../../resources', __FILE__)
elsif File.exists?('/usr/share/ruby-json-schema/resources')
resources = 'usr/share/ruby-json-schema/resources'
else
resources = File.expand_path('../../../../../../share/ruby-json-schema/resources', __FILE__)
end
File.join(resources, @metaschema_name)
end
end
end
end
|