Exception: Castkit::AttributeError

Inherits:
Error
  • Object
show all
Defined in:
lib/castkit/error.rb

Overview

Raised for attribute validation, access, or casting failures.

Instance Method Summary collapse

Methods inherited from Error

#context, #initialize

Constructor Details

This class inherits a constructor from Castkit::Error

Instance Method Details

#fieldSymbol?

Returns the field name related to the error, if available.



32
33
34
# File 'lib/castkit/error.rb', line 32

def field
  context.is_a?(Hash) ? context[:field] : context || nil
end

#to_sString

Formats the error message with field info if available.



39
40
41
42
# File 'lib/castkit/error.rb', line 39

def to_s
  field_info = field ? " (on #{field})" : ""
  "#{super}#{field_info}"
end