class InputSanitizer::V2::ErrorCollection

Attributes

error_codes[R]
messages[R]

Public Class Methods

new(errors) click to toggle source
# File lib/input_sanitizer/v2/error_collection.rb, line 6
def initialize(errors)
  @error_codes = {}
  @messages = {}
  @error_details = {}

  errors.each do |error|
    (@error_codes[error.field] ||= []) << error.code
    (@messages[error.field] ||= []) << error.message
    error_value_hash = { :value => error.value }
    (@error_details[error.field] ||= []) << error_value_hash
  end
end

Public Instance Methods

[](attribute) click to toggle source
# File lib/input_sanitizer/v2/error_collection.rb, line 19
def [](attribute)
  @error_codes[attribute]
end
add(attribute, code = :invalid, options = {}) click to toggle source
# File lib/input_sanitizer/v2/error_collection.rb, line 39
def add(attribute, code = :invalid, options = {})
  (@error_codes[attribute] ||= []) << code
  (@messages[attribute] ||= []) << options.delete(:messages)
  (@error_details[attribute] ||= []) << options
end
count()
Alias for: size
each() { |attribute, error| ... } click to toggle source
# File lib/input_sanitizer/v2/error_collection.rb, line 23
def each
  @error_codes.each_key do |attribute|
    self[attribute].each { |error| yield attribute, error }
  end
end
empty?() click to toggle source
# File lib/input_sanitizer/v2/error_collection.rb, line 35
def empty?
  @error_codes.empty?
end
full_messages()
Alias for: to_hash
length()
Alias for: size
size() click to toggle source
# File lib/input_sanitizer/v2/error_collection.rb, line 29
def size
  @error_codes.size
end
Also aliased as: length, count
to_hash() click to toggle source
# File lib/input_sanitizer/v2/error_collection.rb, line 45
def to_hash
  messages.dup
end
Also aliased as: full_messages