Sha256: 9a7b617f193ffc0671df4c63c7bf6f121f3ac9612d103697b218dc5b9a8d1a4a

Contents?: true

Size: 708 Bytes

Versions: 4

Compression:

Stored size: 708 Bytes

Contents

module JsonSchema
  class SchemaError
    attr_accessor :message, :schema, :type

    def self.aggregate(errors)
      errors.map(&:to_s)
    end

    def initialize(schema, message, type)
      @schema = schema
      @message = message
      @type = type
    end

    def to_s
      "#{schema.pointer}: #{message}"
    end
  end

  class ValidationError < SchemaError
    attr_accessor :path, :sub_errors

    def initialize(schema, path, message, type, sub_errors = nil)
      super(schema, message, type)
      @path = path
      @sub_errors = sub_errors
    end

    def pointer
      path.join("/")
    end

    def to_s
      "#{pointer}: failed schema #{schema.pointer}: #{message}"
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
json_schema-0.6.2 lib/json_schema/schema_error.rb
json_schema-0.6.1 lib/json_schema/schema_error.rb
json_schema-0.6.0 lib/json_schema/schema_error.rb
json_schema-0.5.0 lib/json_schema/schema_error.rb