Sha256: 96906beb7d08b2fb45f594c7bc7edf304cc4968645989eda7c05ff47b4c686ad

Contents?: true

Size: 846 Bytes

Versions: 2

Compression:

Stored size: 846 Bytes

Contents

module JsonSchema
  class SchemaError
    attr_accessor :message
    attr_accessor :schema

    def self.aggregate(errors)
      # May want to eventually use a JSON Pointer instead to help user narrow
      # down the location of the error. It's slightly tricky to ascend the
      # schema hierarchy to raise build one though, so I'm punting on that
      # for now.
      errors.map { |e|
        if e.schema
          %{#{e.schema.pointer}: #{e.message}}
        else
          e.message
        end
      }.join(" ")
    end

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

  class ValidationError < SchemaError
    attr_accessor :path

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

    def pointer
      path.join("/")
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
json_schema-0.0.12 lib/json_schema/schema_error.rb
json_schema-0.0.11 lib/json_schema/schema_error.rb