Class: Lutaml::Xml::TypeNamespaceResolver
- Inherits:
-
Object
- Object
- Lutaml::Xml::TypeNamespaceResolver
- Defined in:
- lib/lutaml/xml/type_namespace_resolver.rb
Overview
Resolves type namespace references from attributes
LAZY RESOLUTION (Session 126): Type namespaces are resolved during declaration planning, not collection. This prevents infinite recursion: collection → type_namespace_class → imports → new collection Safe to call type_namespace_class during planning - all mappings already imported.
Instance Method Summary collapse
-
#initialize(register = nil) ⇒ TypeNamespaceResolver
constructor
Initialize resolver with register for type resolution.
-
#resolve(needs) ⇒ void
Resolve type namespace references collected during NamespaceCollector phase.
Constructor Details
#initialize(register = nil) ⇒ TypeNamespaceResolver
Initialize resolver with register for type resolution
20 21 22 |
# File 'lib/lutaml/xml/type_namespace_resolver.rb', line 20 def initialize(register = nil) @register = register || Lutaml::Model::Config.default_register end |
Instance Method Details
#resolve(needs) ⇒ void
This method returns an undefined value.
Resolve type namespace references collected during NamespaceCollector phase
Populates needs.type_namespaces, needs.type_namespace_classes, needs.type_attribute_namespaces, needs.type_element_namespaces from needs.type_refs
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/lutaml/xml/type_namespace_resolver.rb', line 32 def resolve(needs) type_refs = needs.type_refs return unless type_refs&.any? type_refs.each do |ref| attr_rule = ref.rule context = ref.context # Resolve type using Reference's mapper_class-aware register resolution type_ns_class = ref.namespace_class(@register) next unless type_ns_class # Populate needs just like collector would have needs.add_type_namespace(attr_rule.to, type_ns_class) if context == :attribute needs.add_type_attribute_namespace(type_ns_class) usage = :attributes else needs.add_type_element_namespace(type_ns_class) usage = :elements end # Track in namespaces hash key = type_ns_class.to_key usage_obj = needs.namespace(key) || NamespaceUsage.new(type_ns_class) usage_obj.used_in << usage needs.add_namespace(key, usage_obj) end # Clear type_refs after resolution (no longer needed) needs.clear_type_refs # Recursively resolve children needs.children&.each_value do |child_needs| resolve(child_needs) end end |