Add transform modifier to support value transformations#28
Merged
Conversation
- 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.
- 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.
This comment was marked as outdated.
This comment was marked as outdated.
- 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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.