Class: JSON::Schema::Validator

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

Direct Known Subclasses

Draft1, Draft2, Draft3, Draft4, Draft6

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeValidator

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

#attributesObject

Returns the value of attribute attributes.



4
5
6
# File 'lib/json-schema/schema/validator.rb', line 4

def attributes
  @attributes
end

#default_formatsObject (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

#formatsObject

Returns the value of attribute formats.



4
5
6
# File 'lib/json-schema/schema/validator.rb', line 4

def formats
  @formats
end

#namesObject

Returns the value of attribute names.



4
5
6
# File 'lib/json-schema/schema/validator.rb', line 4

def names
  @names
end

#uriObject

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

#metaschemaObject



31
32
33
34
# File 'lib/json-schema/schema/validator.rb', line 31

def metaschema
  resources = File.expand_path('../../../../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, 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