Add custom type support for object attributes via type: option#47
Add custom type support for object attributes via type: option#47
type: option#47Conversation
- Create ValueExtractor class for polymorphic Hash/PORO access - Add type: option to OptionNormalizer for normalization - Add custom_type and custom_type? methods to Attribute::Base - Extend TypeValidator with custom type validation and schema checks - Add I18n keys for class type mismatch errors - Update NestedObjectValidator to use ValueExtractor - Extend NestedArrayValidator with object :_self pattern support - Extend NestedTransformer for three array types (simple, self-object, complex)
- Renamed `self_attr` to `self_object_attribute` for clearer intent. - Updated methods in `NestedTransformer` and `NestedArrayValidator` to use the new naming convention. - Improved code readability by aligning variables with self-object context.
- Added comprehensive RSpec tests for `ValueExtractor` to verify support for Hash, Struct, OpenStruct, custom PORO, and Data objects. - Expanded `TypeValidator` test suite with custom type validation, including error handling, custom error messages, and lambda-based error message generation. - Ensured compatibility with anonymous classes, Struct, and Data objects. - Covered edge cases for nil, Hash, and non-object attribute types in `TypeValidator`.
- Marked edge case spec with `:aggregate_failures` in `TypeValidator` to allow grouped assertions. - Updated comments in `TypeValidator` specs for clarity on handling anonymous classes. - Removed tests for `OpenStruct` in `ValueExtractor` to simplify the test suite and avoid reliance on deprecated structures. - Renamed context description in `ValueExtractor` tests for edge cases.
- Introduced `self_object_attribute` method to cache and optimize access to the self-object attribute. - Updated `validate_regular_array_item!` to use the new method for better clarity and consistency. - Improved edge case handling by falling back to `inspect` if `expected_class.name` is nil in `TypeValidator`.
- Introduced `ConditionalProcessing` module in `lib/treaty/entity/attribute/validation/concerns` to handle `:if` and `:unless` options for nested transformers. - Moved duplicated conditional logic from `ObjectTransformer` and `ArrayTransformer` into the new concern. - Updated `ObjectTransformer` and `ArrayTransformer` to include `ConditionalProcessing` for shared functionality. - Added comprehensive RSpec tests for `ConditionalProcessing`, ensuring coverage for mutual exclusivity, caching, and conditional evaluation.
- Updated documentation to introduce the `type:` option for object attributes, allowing values to be instances of a custom class. - Added examples for defining and validating custom types in nested structures. - Expanded troubleshooting section with error scenarios and solutions for improper `type:` usage. - Improved i18n messages to include `type:`-related error handling. - Enhanced cheatsheet and API reference with concise `type:` usage examples.
- Added detailed explanations and examples for `:_self` pattern in arrays. - Expanded documentation on using `type:` option for validating array items as specific class instances or hashes. - Updated guides, references, and the cheatsheet with relevant examples, covering validation, use cases, and polymorphic acceptance details.
- Expanded documentation on the `type:` option for class instance validation. - Added detailed examples combining `type:` with `use_entity` for reusable, type-safe nested attributes. - Clarified behavior when `type:` is specified (only instances accepted, not hashes) across guides, API reference, and cheatsheet. - Improved explanations for scenarios involving typed objects and array handling.
🔍 Code Review - PR #47: Add custom type support for object attributes via
|
No description provided.