Class: EasyTalk::ErrorFormatter::Base Abstract
- Inherits:
-
Object
- Object
- EasyTalk::ErrorFormatter::Base
- Defined in:
- lib/easy_talk/error_formatter/base.rb
Overview
Subclass and implement #format to create a formatter.
Abstract base class for error formatters.
Provides common functionality for transforming ActiveModel::Errors
into standardized formats. Subclasses implement the format method
to produce specific output formats.
Direct Known Subclasses
Instance Attribute Summary collapse
-
#errors ⇒ Object
readonly
Returns the value of attribute errors.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Instance Method Summary collapse
-
#error_entries ⇒ Array<Hash>
protected
Build a normalized list of error entries from ActiveModel::Errors.
-
#format ⇒ Hash, Array
abstract
Format the errors into the target format.
-
#include_codes? ⇒ Boolean
protected
Check if error codes should be included in the output.
-
#initialize(errors, options = {}) ⇒ Base
constructor
Initialize a new formatter.
Constructor Details
#initialize(errors, options = {}) ⇒ Base
Initialize a new formatter.
30 31 32 33 |
# File 'lib/easy_talk/error_formatter/base.rb', line 30 def initialize(errors, = {}) @errors = errors @options = end |
Instance Attribute Details
#errors ⇒ Object (readonly)
Returns the value of attribute errors.
23 24 25 |
# File 'lib/easy_talk/error_formatter/base.rb', line 23 def errors @errors end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
23 24 25 |
# File 'lib/easy_talk/error_formatter/base.rb', line 23 def @options end |
Instance Method Details
#error_entries ⇒ Array<Hash> (protected)
Build a normalized list of error entries from ActiveModel::Errors.
Each entry contains:
- :attribute - The attribute name (may include dots for nested)
- :message - The error message
- :full_message - The full error message with attribute name
- :type - The error type from errors.details (e.g., :blank, :too_short)
- :detail_options - Additional options from the error detail
63 64 65 |
# File 'lib/easy_talk/error_formatter/base.rb', line 63 def error_entries @error_entries ||= build_error_entries end |
#format ⇒ Hash, Array
Format the errors into the target format.
40 41 42 |
# File 'lib/easy_talk/error_formatter/base.rb', line 40 def format raise NotImplementedError, "#{self.class} must implement #format" end |
#include_codes? ⇒ Boolean (protected)
Check if error codes should be included in the output.
49 50 51 |
# File 'lib/easy_talk/error_formatter/base.rb', line 49 def include_codes? @options.fetch(:include_codes, EasyTalk.configuration.include_error_codes) end |