Sha256: 791f52063d6fcefb42390577671c30c22932e05fa8fd2327c198a1a73b7ac9c2

Contents?: true

Size: 1.05 KB

Versions: 11

Compression:

Stored size: 1.05 KB

Contents

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

11 entries across 11 versions & 1 rubygems

Version Path
json-schema-2.2.5 lib/json-schema/attributes/not.rb
json-schema-2.2.4 lib/json-schema/attributes/not.rb
json-schema-2.2.3 lib/json-schema/attributes/not.rb
json-schema-2.2.2 lib/json-schema/attributes/not.rb
json-schema-2.2.1 lib/json-schema/attributes/not.rb
json-schema-2.2.0 lib/json-schema/attributes/not.rb
json-schema-2.1.9 lib/json-schema/attributes/not.rb
json-schema-2.1.8 lib/json-schema/attributes/not.rb
json-schema-2.1.7 lib/json-schema/attributes/not.rb
json-schema-2.1.6 lib/json-schema/attributes/not.rb
json-schema-2.1.5 lib/json-schema/attributes/not.rb