Exception: Safire::Errors::ValidationError
- Defined in:
- lib/safire/errors.rb
Overview
Raised for input validation errors.
Instance Attribute Summary collapse
-
#attribute ⇒ Symbol?
readonly
The attribute that failed validation.
-
#reason ⇒ String?
readonly
Why validation failed.
Instance Method Summary collapse
-
#initialize(attribute: nil, reason: nil) ⇒ ValidationError
constructor
A new instance of ValidationError.
Constructor Details
#initialize(attribute: nil, reason: nil) ⇒ ValidationError
Returns a new instance of ValidationError.
228 229 230 231 232 |
# File 'lib/safire/errors.rb', line 228 def initialize(attribute: nil, reason: nil) @attribute = attribute @reason = reason super() end |
Instance Attribute Details
#attribute ⇒ Symbol? (readonly)
Returns the attribute that failed validation.
225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 |
# File 'lib/safire/errors.rb', line 225 class ValidationError < Error attr_reader :attribute, :reason def initialize(attribute: nil, reason: nil) @attribute = attribute @reason = reason super() end private def if @attribute && @reason "Validation failed for #{@attribute}: #{@reason}" elsif @attribute "Validation failed for #{@attribute}" else 'Validation error' end end end |
#reason ⇒ String? (readonly)
Returns why validation failed.
225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 |
# File 'lib/safire/errors.rb', line 225 class ValidationError < Error attr_reader :attribute, :reason def initialize(attribute: nil, reason: nil) @attribute = attribute @reason = reason super() end private def if @attribute && @reason "Validation failed for #{@attribute}: #{@reason}" elsif @attribute "Validation failed for #{@attribute}" else 'Validation error' end end end |