Class: EasyTalk::ErrorFormatter::PathConverter
- Inherits:
-
Object
- Object
- EasyTalk::ErrorFormatter::PathConverter
- Defined in:
- lib/easy_talk/error_formatter/path_converter.rb
Overview
Converts attribute paths between different formats.
EasyTalk uses dot notation for nested model errors (e.g., "email.address"). This class converts those paths to different standard formats:
- JSON Pointer (RFC 6901): /properties/email/properties/address
- JSON:API: /data/attributes/email/address
- Flat: email.address (unchanged)
Class Method Summary collapse
-
.to_flat(attribute) ⇒ String
Return the attribute path as-is (flat format).
-
.to_json_pointer(attribute) ⇒ String
Convert an attribute path to JSON Schema pointer format.
-
.to_jsonapi_pointer(attribute, prefix: '/data/attributes') ⇒ String
Convert an attribute path to JSON:API pointer format.
Class Method Details
.to_flat(attribute) ⇒ String
Return the attribute path as-is (flat format).
47 48 49 |
# File 'lib/easy_talk/error_formatter/path_converter.rb', line 47 def to_flat(attribute) attribute.to_s end |
.to_json_pointer(attribute) ⇒ String
Convert an attribute path to JSON Schema pointer format.
26 27 28 29 30 31 |
# File 'lib/easy_talk/error_formatter/path_converter.rb', line 26 def to_json_pointer(attribute) parts = attribute.to_s.split('.') return "/properties/#{parts.first}" if parts.length == 1 parts.map { |part| "/properties/#{part}" }.join end |
.to_jsonapi_pointer(attribute, prefix: '/data/attributes') ⇒ String
Convert an attribute path to JSON:API pointer format.
38 39 40 41 |
# File 'lib/easy_talk/error_formatter/path_converter.rb', line 38 def to_jsonapi_pointer(attribute, prefix: '/data/attributes') parts = attribute.to_s.split('.') "#{prefix}/#{parts.join('/')}" end |