Skip to content

Add transform modifier to support value transformations#28

Merged
afuno merged 7 commits intomainfrom
feature/transform
Nov 22, 2025
Merged

Add transform modifier to support value transformations#28
afuno merged 7 commits intomainfrom
feature/transform

Conversation

@afuno
Copy link
Member

@afuno afuno commented Nov 22, 2025

No description provided.

- Introduced `TransformModifier` to enable custom lambda-based value transformations during request/response processing.
- Ensured all transformation logic adheres to strict validation and error handling via `Treaty::Exceptions::Validation`.
- Updated related specs to test scenarios like schema validation, successful transformations, and error handling cases.
- Documented usage examples in `transformation.md` including request, response, and advanced transformation modes.
- Registered the `transform` modifier within the modifier registry.
- Enhanced localization files to support custom error messages for the `transform` modifier.

This change enhances attribute value preprocessing and postprocessing with flexible transformation support.
- Added detailed RSpec tests for various Treaty modifiers (`AsModifier`, `DefaultModifier`) ensuring schema validation, value transformation, and edge case handling.
- Introduced exhaustive tests for validators (`FormatValidator`, `InclusionValidator`, `RequiredValidator`) verifying format-specific validations, inclusion rules, and presence requirements.
- Covered multiple data types (e.g., String, Integer, Boolean, Proc) and ensured proper error handling with `Treaty::Exceptions::Validation`.
- Improved test coverage to validate expected behaviors, dynamic transformations, and custom error messages.
- These tests ensure the reliability and robustness of Treaty’s attribute option functionalities.
- Updated `FormatValidator` to support parsing multiple date formats including `DD/MM/YYYY` and `YYYY/MM/DD`. Removed rejection of previously considered invalid formats.
- Enhanced duration validation to strictly adhere to ISO 8601 format, rejecting non-compliant durations like "1 day" while supporting additional valid cases such as `P1W` and `PT1H30M`.
- Adjusted `DefaultModifier` for improved Proc default handling by removing unnecessary nil-return lambda definition.
- Streamlined `TransformModifier` lambda calls by simplifying the invocation syntax with Ruby 2.7+ shorthand style.
- Updated RSpec tests across various validators and modifiers to include `:aggregate_failures`, ensuring grouped expectation errors are reported together.
- Adjusted test descriptions, maintaining consistency and readability.
- Refactored minor contexts to use `describe` for better conceptual grouping.
- Enhanced code annotations for edge case scenarios and lambda-based transformations, ensuring robust validations during error conditions.
@afuno afuno added this to the v1.0.0 milestone Nov 22, 2025
@afuno afuno self-assigned this Nov 22, 2025
@afuno afuno added the feature label Nov 22, 2025
- Removed redundant context and expectations from `index_treaty_spec`, clarifying test purpose and reducing noise.
- Updated `create_treaty_spec` to improve test readability and ensure structured validation of transformed title.
- Enhanced grouping and annotations in affected specs to maintain consistency.
@afuno afuno added the claude label Nov 22, 2025
@claude

This comment was marked as outdated.

@afuno afuno removed the claude label Nov 22, 2025
- Added detailed examples for the `transform` modifier in `attributes.md`, showcasing both simple and advanced modes with custom error messages.
- Updated `api-reference.md` to define the `transform` modifier, its requirements, and examples of lambda-based transformations.
- Highlighted key details, including error handling with `Treaty::Exceptions::Validation` and processing order relative to validations.
- Linked to new sections in the transformation guide for further reference.
- Updated `TransformModifier` to bypass transformation for nil values, delegating handling to the required validator.
- Updated documentation (`transformation.md`, `attributes.md`, `api-reference.md`) to clarify that transformations apply only to non-nil values.
- Added specs to test and verify that nil values are passed through unchanged without invoking the lambda.
- Improved inline comments for better code understanding and maintenance.
@afuno afuno marked this pull request as ready for review November 22, 2025 18:15
@afuno afuno merged commit 7156173 into main Nov 22, 2025
23 checks passed
@afuno afuno deleted the feature/transform branch November 22, 2025 18:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant