Exception: InputSanitizer::TypeMismatchError

Inherits:
ValidationError show all
Defined in:
lib/input_sanitizer/errors.rb

Instance Attribute Summary

Attributes inherited from ValidationError

#field, #value

Instance Method Summary collapse

Constructor Details

#initialize(value, type) ⇒ TypeMismatchError

Returns a new instance of TypeMismatchError.



66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/input_sanitizer/errors.rb', line 66

def initialize(value, type)
  @value = value
  @type = type

  message = case @type
  when :integer
    "must be an integer"
  when :url
    'must be a valid URI (include the scheme name part, both http and https are accepted, '\
    'and the hierarchical part)'
  else
    "must be a value of type '#{type}'"
  end

  super(message)
end

Instance Method Details

#codeObject



55
56
57
58
59
60
61
62
63
64
# File 'lib/input_sanitizer/errors.rb', line 55

def code
  case @type
  when :integer
    :not_an_integer
  when :url
    :invalid_uri
  else
    :invalid_type
  end
end