Class: JSON::Schema::Validator

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

Direct Known Subclasses

Draft1, Draft2, Draft3, Draft4

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeValidator



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
# File 'lib/json-schema/schema/validator.rb', line 16

def extend_schema_definition(schema_uri)
  validator = JSON::Validator.validator_for(schema_uri)
  @attributes.merge!(validator.attributes)
end

#metaschemaObject



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

def metaschema
  resources = File.expand_path('../../../../resources', __FILE__)
  File.join(resources, @metaschema_name)
end

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



21
22
23
24
25
26
27
28
# File 'lib/json-schema/schema/validator.rb', line 21

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