Class: JSON::Schema::Validator

Inherits:
Object
  • Object
show all
Defined in:
lib/json-schema/validator.rb

Direct Known Subclasses

Draft1, Draft2, Draft3, Draft4

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeValidator

Returns a new instance of Validator


74
75
76
77
# File 'lib/json-schema/validator.rb', line 74

def initialize()
  @attributes = {}
  @uri = nil
end

Instance Attribute Details

#attributesObject

Returns the value of attribute attributes


72
73
74
# File 'lib/json-schema/validator.rb', line 72

def attributes
  @attributes
end

#uriObject

Returns the value of attribute uri


72
73
74
# File 'lib/json-schema/validator.rb', line 72

def uri
  @uri
end

Instance Method Details

#extend_schema_definition(schema_uri) ⇒ Object


79
80
81
82
83
84
85
86
# File 'lib/json-schema/validator.rb', line 79

def extend_schema_definition(schema_uri)
  u = URI.parse(schema_uri)
  validator = JSON::Validator.validators["#{u.scheme}://#{u.host}#{u.path}"]
  if validator.nil?
    raise SchemaError.new("Schema not found: #{u.scheme}://#{u.host}#{u.path}")
  end
  @attributes.merge!(validator.attributes)
end

#to_sObject


88
89
90
# File 'lib/json-schema/validator.rb', line 88

def to_s
  "#{@uri.scheme}://#{uri.host}#{uri.path}"
end

#validate(current_schema, data, fragments, processor, options = {}) ⇒ Object


92
93
94
95
96
97
98
99
# File 'lib/json-schema/validator.rb', line 92

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