Class: Owasp::Esapi::Validator::ValidatorErrorList
- Inherits:
-
Object
- Object
- Owasp::Esapi::Validator::ValidatorErrorList
- Defined in:
- lib/validator/validator_error_list.rb
Overview
List of Validation exceptions this list is indexed by the context
Instance Method Summary collapse
-
#<<(error) ⇒ Object
Add an error to the list.
-
#empty? ⇒ Boolean
Return true if this list is empty.
-
#errors ⇒ Object
Return the array of errors in this list.
-
#initialize ⇒ ValidatorErrorList
constructor
Create a new list.
-
#size ⇒ Object
Return the size of the list.
Constructor Details
#initialize ⇒ ValidatorErrorList
Create a new list
9 10 11 |
# File 'lib/validator/validator_error_list.rb', line 9 def initialize() @errors = {} end |
Instance Method Details
#<<(error) ⇒ Object
Add an error to the list. We will raise ArgumentException if any of the following is true:
-
error is nil
-
context is nil
-
we already have an error for the given context
-
the error isnt a ValidationException
18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/validator/validator_error_list.rb', line 18 def <<(error) raise ArgumentError.new("Invalid Error") if error.nil? if error.instance_of?(ValidationException) context = error.context raise ArgumentError.new("Invalid context") if context.nil? raise ArgumentError.new("Duplicate error") if @errors.has_key?(context) @errors[context] = error else raise ArgumentError.new("Exception was not a ValdiaitonException") end end |
#empty? ⇒ Boolean
Return true if this list is empty
31 32 33 |
# File 'lib/validator/validator_error_list.rb', line 31 def empty? @errors.empty? end |
#errors ⇒ Object
Return the array of errors in this list
41 42 43 |
# File 'lib/validator/validator_error_list.rb', line 41 def errors @errors.values end |
#size ⇒ Object
Return the size of the list
36 37 38 |
# File 'lib/validator/validator_error_list.rb', line 36 def size @errors.size end |