Moved attribute value resolution to Attribute class#709
Draft
HassanAkbar wants to merge 1 commit into
Draft
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR implements issue #46 by consolidating attribute default resolution and value-map handling into Lutaml::Model::Attribute, and removing the now-redundant DefaultValueResolver service. It also refactors custom-method serialization call sites to use small helper methods and adds regression specs to lock in edge-case behavior.
Changes:
- Move default resolution behavior (default presence checks, proc execution in instance context, casting usage at call sites) off
Services::DefaultValueResolverand intoAttributemethods. - Move/centralize value-map application into
Attribute#apply_value_map, updating transform/serialization codepaths to delegate to it. - Add regression tests around nil/omitted handling and value-map behavior; remove tests and code for
DefaultValueResolver.
Reviewed changes
Copilot reviewed 20 out of 20 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| spec/lutaml/model/transform_apply_value_map_spec.rb | Adds regression coverage for Transform#apply_value_map when attr is nil (custom-method-only rules). |
| spec/lutaml/model/services/default_value_resolver_spec.rb | Removes specs for the deleted DefaultValueResolver service. |
| spec/lutaml/model/rule_value_extractor_spec.rb | Updates tests to use real Attribute + default register now that defaults resolve via Attribute. |
| spec/lutaml/model/attribute_spec.rb | Adds/updates specs to validate default resolution, caching behavior, and validate_value! threading instance context. |
| spec/lutaml/model/attribute_apply_value_map_spec.rb | Adds focused coverage for Attribute#apply_value_map across nil/empty/omitted and boolean map formats. |
| lib/lutaml/xml/document.rb | Extracts apply_custom_to helper for XML serialization custom-method dispatch. |
| lib/lutaml/xml/adapter/plan_based_builder.rb | Uses apply_custom_to helper instead of repeating public_send dispatch logic. |
| lib/lutaml/xml/adapter/base_adapter.rb | Uses apply_custom_to helper for content mapping custom-method serialization. |
| lib/lutaml/model/validation.rb | Removes DefaultValueResolver usage; validates using instance_object: threading to Attribute#validate_value!. |
| lib/lutaml/model/transform.rb | Delegates value-map application to Attribute#apply_value_map, with a safe fallback for attr-less rules. |
| lib/lutaml/model/services/rule_value_extractor.rb | Removes DefaultValueResolver usage; pulls defaults via Attribute#default_value. |
| lib/lutaml/model/services/default_value_resolver.rb | Deletes the DefaultValueResolver service implementation. |
| lib/lutaml/model/services.rb | Removes autoload entry for the deleted service. |
| lib/lutaml/model/serialize/value_mapping.rb | Delegates value-map application to Attribute#apply_value_map. |
| lib/lutaml/model/serialize.rb | Updates default determination to resolve raw default once, then cast, avoiding prior double-proc execution. |
| lib/lutaml/model/schema/generator/property.rb | Switches schema default extraction to Attribute#default_value + cast instead of the removed service. |
| lib/lutaml/model/mapping/mapping_rule.rb | Removes unused serialize_attribute helper (custom serialization already handled elsewhere). |
| lib/lutaml/model/attribute.rb | Adds Attribute#apply_value_map and updates validate_value! to resolve defaults via attribute methods. |
| lib/lutaml/key_value/transformation.rb | Refactors serialize-side custom-method invocation into an apply_custom_to helper. |
| lib/lutaml/key_value/transform.rb | Refactors serialize-side custom-method invocation into an apply_custom_to helper and simplifies custom-method deserialization dispatch. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
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.
fixes #46