Skip to content

Moved attribute value resolution to Attribute class#709

Draft
HassanAkbar wants to merge 1 commit into
mainfrom
feat/attribute-value-consolidation
Draft

Moved attribute value resolution to Attribute class#709
HassanAkbar wants to merge 1 commit into
mainfrom
feat/attribute-value-consolidation

Conversation

@HassanAkbar

Copy link
Copy Markdown
Member

fixes #46

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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::DefaultValueResolver and into Attribute methods.
  • 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Consolidate attribute value loading functionality in the Attribute class (custom methods, defaults, casting)

2 participants