Add conditional attributes support via if option#32
Merged
Conversation
- Introduced `if` option to conditionally include attributes based on runtime data. - Implemented `Base` class and `IfConditional` for defining and processing conditionals. - Updated the registry to include conditionals as a new category. - Enhanced validation orchestrator to skip attributes when condition evaluates to `false`. - Documented `if` option usage, examples, and best practices in `attributes.md`. - Localized error messages for `if` conditionals in configuration files. - Added tests to demonstrate usage of `if` option with conditional attributes.
- Replaced `published_at` condition checks with `status`-based logic across attributes. - Introduced `views`, `draft_notes`, and `priority` attributes with refined visibility rules. - Enhanced conditional metadata for `draft` and `published` status in articles. - Expanded analytics logic to depend on view count presence. - Updated `attributes.md` to reflect the new conditional handling and examples. - Adjusted test cases in `create_treaty.rb` to align with updated attribute conditions.
- Implemented `status`-driven logic for conditional attributes in `CreateTreaty`. - Expanded request and response structures to include `rating`, `views`, `draft_notes`, and `tags` with new visibility rules based on post status. - Added detailed examples and guidance to `examples.md` and `cheatsheet.md`. - Updated test cases in `create_treaty_spec.rb` to reflect conditional attribute handling. - Documented the `if` option in `api-reference.md` with key usage scenarios.
- Replaced all single quotes in `if` conditions with double quotes for consistency across documentation and code examples. - Updated examples in `examples.md`, `cheatsheet.md`, and `api-reference.md` to align with the new quoting style. - Adjusted condition-based logic in `attributes.md` and `create_treaty.rb` to use double quotes. - Simplified nested and runtime conditional examples for better readability. - Ensured test cases reflect the updated conditional formatting.
- Updated conditional parameter name in `Base#evaluate_condition` to `_data` for clarity and to indicate unused parameter. - Refactored multiline attribute definition in `CreateTreaty` for improved readability and consistency with status-based conditionals. - Disabled RuboCop's `MethodLength` check on `Base#validate!` for logic clarity. - Ensured alignment with code style conventions across the codebase.
- Updated `validation.md` with the revised attribute validation order that prioritizes conditional evaluation. - Added detailed troubleshooting examples for conditional attribute errors, including common issues, best practices, and tips in `troubleshooting.md`. - Enhanced clarity around `if` option usage, safe navigation, and lambda expectations in documentation. - Improved guidelines on avoiding common pitfalls when implementing conditional attributes.
- Added new error messages for `cast` option, covering invalid types, unsupported source/target conversions, and conversion errors. - Included localized error messages for `if` option, addressing invalid types and evaluation errors. - Updated `internationalization.md` with detailed translations to improve clarity and support for edge cases.
- Added new localized error messages for type mismatches, including boolean attributes and detailed YAML definitions for versioning. - Extended internationalization support with translations for handling version deprecation, multiple defaults, and invalid default options. - Updated `internationalization.md` to include examples and improve documentation clarity.
This comment was marked as outdated.
This comment was marked as outdated.
- Implemented caching for conditional processors using `conditionals_for_attributes` to improve performance. - Validated `if` option schemas at definition time instead of runtime, reducing redundant validations. - Simplified conditional evaluation in `Base#evaluate_condition` with pre-built processors. - Added `build_conditionals_for_attributes` to construct and cache all `if` conditionals upfront. - Improved code clarity and reduced duplication by centralizing conditional processor logic.
This comment was marked as outdated.
This comment was marked as outdated.
- Introduced `NON_NORMALIZABLE_OPTIONS` constant in `OptionNormalizer` to identify options that bypass normalization (e.g., `if` conditionals). - Added logic to skip normalization for non-normalizable options in the `normalize_options` method. - Implemented `should_process_attribute?` in `NestedTransformer` to handle `if` conditionals, ensuring attributes are processed only when conditions evaluate to true. - Enhanced error handling for conditional evaluation failures to safely skip attributes. - Improved clarity and maintainability by centralizing and refining conditional handling logic.
- Removed `NON_NORMALIZABLE_OPTIONS` constant and associated comments as they are no longer used. - Cleaned up redundant conditional logic in `normalize_options` method. - Simplified code by streamlining normalization process and adhering to current logic.
- Introduced `conditionals_for_attributes` method to cache and reuse conditional processors, improving performance. - Added `build_conditionals_for_attributes` to pre-build all `if` conditionals during validation. - Validated `if` option schemas at definition time, reducing runtime overhead and improving reliability. - Simplified `should_process_attribute?` by leveraging cached processors for conditional evaluation. - Reduced duplication and improved code clarity by centralizing conditional processor logic.
- Added context for version 6 to cover `published` and `draft` post scenarios. - Validated handling of `published_at` and `tags` for `published` posts. - Ensured `draft` posts process without `published_at` and `tags`. - Improved test coverage for conditional attribute handling.
- Added specs for `Base` and `IfConditional` classes in `Treaty::Attribute::Option::Conditionals`, ensuring robust testing for conditional attribute handling. - Validated schema for `if` options, covering callable and non-callable scenarios while raising descriptive validation errors. - Covered `evaluate_condition` with diverse data structures, truthy/falsy edge cases, and complex nested conditions. - Included exception wrapping in validation errors for runtime evaluation failures. - Assured `transform_value` and `validate_value!` work as pass-throughs unless overridden.
- Replaced `:test_attr` with `:test_attribute` across spec files to standardize attribute naming. - Updated variable names in `NestedTransformer` (`self_attr` to `self_attribute`) for consistency. - Ensured all affected test cases validate messages and behavior with the updated attribute name.
- Replaced all occurrences of `Time.now` with `Time.current` in documentation examples, ensuring consistency and timezone-awareness. - Updated related test cases in specs to use `Time.current` for generating dynamic values in attributes. - Improved clarity in docs by aligning with Rails best practices for working with timezone-sensitive data.
- Introduced `Showcase::DefaultTreaty` with versioning support to handle default values in request and response structures. - Version 1 demonstrates default values applied to the request payload. - Version 2 shifts the default handling to the response payload. - Implemented `delegate_to` using a local lambda for parameter processing. - Added comprehensive specs to validate default values in both request and response for each version. - Ensured seamless transition between versions and robust validation logic in tests.
- Made `status`, `role`, and `email_verified` attributes optional where previously required, aligning with updated schema expectations. - Adjusted default value handling for `status`, `role`, and `email_verified` attributes in schema to maintain consistent behavior. - Updated related tests across serialization, deserialization, and spec files to validate optional attributes. - Fixed redundant `:optional` declarations in filters and improved clarity in schemas.
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.