Exception: JSON::Schema::ValidationError
- Inherits:
-
StandardError
- Object
- StandardError
- JSON::Schema::ValidationError
- Defined in:
- lib/json-schema/errors/validation_error.rb
Constant Summary collapse
- INDENT =
' '
Instance Attribute Summary collapse
-
#failed_attribute ⇒ Object
Returns the value of attribute failed_attribute.
-
#fragments ⇒ Object
Returns the value of attribute fragments.
-
#message ⇒ Object
Returns the value of attribute message.
-
#schema ⇒ Object
Returns the value of attribute schema.
-
#sub_errors ⇒ Object
Returns the value of attribute sub_errors.
Instance Method Summary collapse
-
#initialize(message, fragments, failed_attribute, schema) ⇒ ValidationError
constructor
A new instance of ValidationError.
- #message_with_schema ⇒ Object
- #to_hash ⇒ Object
- #to_string(subschema_level = 0) ⇒ Object
Constructor Details
#initialize(message, fragments, failed_attribute, schema) ⇒ ValidationError
Returns a new instance of ValidationError.
7 8 9 10 11 12 13 14 |
# File 'lib/json-schema/errors/validation_error.rb', line 7 def initialize(, fragments, failed_attribute, schema) @fragments = fragments.clone @schema = schema @sub_errors = {} @failed_attribute = failed_attribute @message = super() end |
Instance Attribute Details
#failed_attribute ⇒ Object
Returns the value of attribute failed_attribute.
5 6 7 |
# File 'lib/json-schema/errors/validation_error.rb', line 5 def failed_attribute @failed_attribute end |
#fragments ⇒ Object
Returns the value of attribute fragments.
5 6 7 |
# File 'lib/json-schema/errors/validation_error.rb', line 5 def fragments @fragments end |
#message ⇒ Object
Returns the value of attribute message.
5 6 7 |
# File 'lib/json-schema/errors/validation_error.rb', line 5 def @message end |
#schema ⇒ Object
Returns the value of attribute schema.
5 6 7 |
# File 'lib/json-schema/errors/validation_error.rb', line 5 def schema @schema end |
#sub_errors ⇒ Object
Returns the value of attribute sub_errors.
5 6 7 |
# File 'lib/json-schema/errors/validation_error.rb', line 5 def sub_errors @sub_errors end |
Instance Method Details
#message_with_schema ⇒ Object
40 41 42 |
# File 'lib/json-schema/errors/validation_error.rb', line 40 def "#{} in schema #{schema.uri}" end |
#to_hash ⇒ Object
29 30 31 32 33 34 35 36 37 38 |
# File 'lib/json-schema/errors/validation_error.rb', line 29 def to_hash base = { schema: @schema.uri, fragment: ::JSON::Schema::Attribute.build_fragment(fragments), message: , failed_attribute: @failed_attribute.to_s.split(':').last.split('Attribute').first } if !@sub_errors.empty? base[:errors] = @sub_errors.each_with_object({}) do |(subschema, errors), hsh| subschema_sym = subschema.downcase.gsub(/\W+/, '_').to_sym hsh[subschema_sym] = Array(errors).map { |e| e.to_hash } end end base end |
#to_string(subschema_level = 0) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/json-schema/errors/validation_error.rb', line 16 def to_string(subschema_level = 0) if @sub_errors.empty? subschema_level == 0 ? : else = ["#{}. The schema specific errors were:\n"] @sub_errors.each do |subschema, errors| .push "- #{subschema}:" .concat(Array(errors).map { |e| "#{INDENT}- #{e.to_string(subschema_level + 1)}" }) end .map { |m| (INDENT * subschema_level) + m }.join("\n") end end |