Class: Owasp::Esapi::Validator::ValidatorErrorList

Inherits:
Object
  • Object
show all
Defined in:
lib/validator/validator_error_list.rb

Overview

List of Validation exceptions this list is indexed by the context

Instance Method Summary collapse

Constructor Details

#initializeValidatorErrorList

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:

  1. error is nil

  2. context is nil

  3. we already have an error for the given context

  4. the error isnt a ValidationException

Raises:

  • (ArgumentError)


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

Returns:

  • (Boolean)


31
32
33
# File 'lib/validator/validator_error_list.rb', line 31

def empty?
  @errors.empty?
end

#errorsObject

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

#sizeObject

Return the size of the list



36
37
38
# File 'lib/validator/validator_error_list.rb', line 36

def size
  @errors.size
end