Exception: Castkit::AttributeError

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

Overview

Raised for attribute validation, access, or casting failures.

Instance Attribute Summary

Attributes inherited from Error

#context

Instance Method Summary collapse

Methods inherited from Error

#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.

Returns:

  • (Symbol, nil)


29
30
31
# File 'lib/castkit/error.rb', line 29

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

#to_sString

Formats the error message with field info if available.

Returns:

  • (String)


36
37
38
39
# File 'lib/castkit/error.rb', line 36

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