Sha256: d47bf2c708faa929b398e8470e0d2eb6e0784787f7609cf5475e0fa38941e515

Contents?: true

Size: 1.08 KB

Versions: 5

Compression:

Stored size: 1.08 KB

Contents

require 'json-schema/attribute'

module JSON
  class Schema
    class NotAttribute < Attribute
      def self.validate(current_schema, data, fragments, processor, validator, options = {})
        schema = JSON::Schema.new(current_schema.schema['not'],current_schema.uri,validator)
        failed = true
        errors_copy = processor.validation_errors.clone

        begin
          schema.validate(data,fragments,processor,options)
          # If we're recording errors, we don't throw an exception. Instead, check the errors array length
          if options[:record_errors] && errors_copy.length != processor.validation_errors.length
            processor.validation_errors.replace(errors_copy)
          else
            message = "The property '#{build_fragment(fragments)}' of type #{data.class} matched the disallowed schema"
            failed = false
          end
        rescue
          # Yay, we failed validation.
        end

        unless failed
          validation_error(processor, message, fragments, current_schema, self, options[:record_errors])
        end
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 2 rubygems

Version Path
json-schema-2.5.2 lib/json-schema/attributes/not.rb
json-schema-openc-fork-0.0.2 lib/json-schema/attributes/not.rb
json-schema-2.5.1 lib/json-schema/attributes/not.rb
json-schema-openc-fork-0.0.1 lib/json-schema/attributes/not.rb
json-schema-2.5.0 lib/json-schema/attributes/not.rb