Class: JSON::Schema::Validator
- Inherits:
-
Object
- Object
- JSON::Schema::Validator
- Defined in:
- lib/json-schema/validator.rb
Instance Attribute Summary collapse
-
#attributes ⇒ Object
Returns the value of attribute attributes.
-
#uri ⇒ Object
Returns the value of attribute uri.
Instance Method Summary collapse
- #extend_schema_definition(schema_uri) ⇒ Object
-
#initialize ⇒ Validator
constructor
A new instance of Validator.
- #to_s ⇒ Object
- #validate(current_schema, data, fragments, processor, options = {}) ⇒ Object
Constructor Details
#initialize ⇒ Validator
Returns a new instance of Validator.
75 76 77 78 |
# File 'lib/json-schema/validator.rb', line 75 def initialize() @attributes = {} @uri = nil end |
Instance Attribute Details
#attributes ⇒ Object
Returns the value of attribute attributes.
73 74 75 |
# File 'lib/json-schema/validator.rb', line 73 def attributes @attributes end |
#uri ⇒ Object
Returns the value of attribute uri.
73 74 75 |
# File 'lib/json-schema/validator.rb', line 73 def uri @uri end |
Instance Method Details
#extend_schema_definition(schema_uri) ⇒ Object
80 81 82 83 84 85 86 87 |
# File 'lib/json-schema/validator.rb', line 80 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_s ⇒ Object
89 90 91 |
# File 'lib/json-schema/validator.rb', line 89 def to_s "#{@uri.scheme}://#{uri.host}#{uri.path}" end |
#validate(current_schema, data, fragments, processor, options = {}) ⇒ Object
93 94 95 96 97 98 99 100 |
# File 'lib/json-schema/validator.rb', line 93 def validate(current_schema, data, fragments, processor, = {}) 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, ) end end data end |