Class: JSON::Schema::Validator
- Inherits:
-
Object
- Object
- JSON::Schema::Validator
- Defined in:
- lib/json-schema/schema/validator.rb
Instance Attribute Summary collapse
-
#attributes ⇒ Object
Returns the value of attribute attributes.
-
#default_formats ⇒ Object
readonly
Returns the value of attribute default_formats.
-
#formats ⇒ Object
Returns the value of attribute formats.
-
#names ⇒ Object
Returns the value of attribute names.
-
#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.
- #metaschema ⇒ Object
- #validate(current_schema, data, fragments, processor, options = {}) ⇒ Object
Constructor Details
#initialize ⇒ Validator
Returns a new instance of Validator.
7 8 9 10 11 12 13 14 |
# File 'lib/json-schema/schema/validator.rb', line 7 def initialize @attributes = {} @formats = {} @default_formats = {} @uri = nil @names = [] @metaschema_name = '' end |
Instance Attribute Details
#attributes ⇒ Object
Returns the value of attribute attributes.
4 5 6 |
# File 'lib/json-schema/schema/validator.rb', line 4 def attributes @attributes end |
#default_formats ⇒ Object (readonly)
Returns the value of attribute default_formats.
5 6 7 |
# File 'lib/json-schema/schema/validator.rb', line 5 def default_formats @default_formats end |
#formats ⇒ Object
Returns the value of attribute formats.
4 5 6 |
# File 'lib/json-schema/schema/validator.rb', line 4 def formats @formats end |
#names ⇒ Object
Returns the value of attribute names.
4 5 6 |
# File 'lib/json-schema/schema/validator.rb', line 4 def names @names end |
#uri ⇒ Object
Returns the value of attribute uri.
4 5 6 |
# File 'lib/json-schema/schema/validator.rb', line 4 def uri @uri end |
Instance Method Details
#extend_schema_definition(schema_uri) ⇒ Object
16 17 18 19 20 |
# File 'lib/json-schema/schema/validator.rb', line 16 def extend_schema_definition(schema_uri) warn '[DEPRECATION NOTICE] The preferred way to extend a Validator is by subclassing, rather than #extend_schema_definition. This method will be removed in version >= 3.' validator = JSON::Validator.validator_for_uri(schema_uri) @attributes.merge!(validator.attributes) end |
#metaschema ⇒ Object
31 32 33 34 |
# File 'lib/json-schema/schema/validator.rb', line 31 def resources = File.('../../../../resources', __FILE__) File.join(resources, @metaschema_name) end |
#validate(current_schema, data, fragments, processor, options = {}) ⇒ Object
22 23 24 25 26 27 28 29 |
# File 'lib/json-schema/schema/validator.rb', line 22 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 |