Exception: JSON::Schema::ValidationError
- Inherits:
-
StandardError
- Object
- StandardError
- JSON::Schema::ValidationError
- Defined in:
- lib/json-schema/validator.rb
Instance Attribute Summary collapse
-
#failed_attribute ⇒ Object
Returns the value of attribute failed_attribute.
-
#fragments ⇒ Object
Returns the value of attribute fragments.
-
#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.
- #to_hash ⇒ Object
- #to_string ⇒ Object
Constructor Details
#initialize(message, fragments, failed_attribute, schema) ⇒ ValidationError
Returns a new instance of ValidationError.
15 16 17 18 19 20 21 22 |
# File 'lib/json-schema/validator.rb', line 15 def initialize(, fragments, failed_attribute, schema) @fragments = fragments.clone @schema = schema @sub_errors = [] @failed_attribute = failed_attribute = "#{} in schema #{schema.uri}" super() end |
Instance Attribute Details
#failed_attribute ⇒ Object
Returns the value of attribute failed_attribute.
13 14 15 |
# File 'lib/json-schema/validator.rb', line 13 def failed_attribute @failed_attribute end |
#fragments ⇒ Object
Returns the value of attribute fragments.
13 14 15 |
# File 'lib/json-schema/validator.rb', line 13 def fragments @fragments end |
#schema ⇒ Object
Returns the value of attribute schema.
13 14 15 |
# File 'lib/json-schema/validator.rb', line 13 def schema @schema end |
#sub_errors ⇒ Object
Returns the value of attribute sub_errors.
13 14 15 |
# File 'lib/json-schema/validator.rb', line 13 def sub_errors @sub_errors end |
Instance Method Details
#to_hash ⇒ Object
34 35 36 37 38 39 40 |
# File 'lib/json-schema/validator.rb', line 34 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.map{|e| e.to_hash} end base end |
#to_string ⇒ Object
24 25 26 27 28 29 30 31 32 |
# File 'lib/json-schema/validator.rb', line 24 def to_string if @sub_errors.empty? else = + "\n The schema specific errors were:\n" @sub_errors.each{|e| = + " - " + e.to_string + "\n"} end end |