Class: JsonSchema::SchemaError

Inherits:
Object
  • Object
show all
Defined in:
lib/json_schema/schema_error.rb

Direct Known Subclasses

ValidationError

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(schema, message) ⇒ SchemaError

Returns a new instance of SchemaError.



20
21
22
23
# File 'lib/json_schema/schema_error.rb', line 20

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

Instance Attribute Details

#messageObject

Returns the value of attribute message.



3
4
5
# File 'lib/json_schema/schema_error.rb', line 3

def message
  @message
end

#schemaObject

Returns the value of attribute schema.



4
5
6
# File 'lib/json_schema/schema_error.rb', line 4

def schema
  @schema
end

Class Method Details

.aggregate(errors) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/json_schema/schema_error.rb', line 6

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