Class: Lutaml::Model::ImportRegistry Private
- Inherits:
-
Object
- Object
- Lutaml::Model::ImportRegistry
- Defined in:
- lib/lutaml/model/import_registry.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
ImportRegistry manages deferred imports with explicit resolution.
This is an INTERNAL class. Users should use Register and GlobalRegister.
Responsibility: Track and resolve deferred type imports
This class:
-
Tracks pending imports per class
-
Resolves imports in correct order (topological)
-
NO TracePoint needed - explicit resolution
-
Tracks resolution state to prevent re-resolution
Defined Under Namespace
Classes: DeferredImport
Instance Attribute Summary collapse
-
#pending_imports ⇒ Hash<Class, Array<DeferredImport>>
readonly
private
Pending imports by owner class.
-
#resolved_classes ⇒ Set<Class>
readonly
private
Classes whose imports have been resolved.
Instance Method Summary collapse
-
#defer(owner_class, method:, symbol:) ⇒ DeferredImport
private
Defer an import for later resolution.
-
#imports_for(owner_class) ⇒ Array<DeferredImport>
private
Get pending imports for a class.
-
#initialize ⇒ ImportRegistry
constructor
private
Create a new ImportRegistry.
-
#pending?(owner_class) ⇒ Boolean
private
Check if a class has pending (unresolved) imports.
-
#pending_classes ⇒ Array<Class>
private
Get all classes with pending imports.
-
#reset! ⇒ void
private
Reset all state (for testing).
-
#resolve(owner_class, context) ⇒ Array<DeferredImport>
private
Resolve all imports for a specific class.
-
#resolve_all!(context) ⇒ Integer
private
Resolve all pending imports.
-
#resolved?(owner_class) ⇒ Boolean
private
Check if a class’s imports are fully resolved.
-
#stats ⇒ Hash
private
Get statistics about the registry.
Constructor Details
#initialize ⇒ ImportRegistry
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Create a new ImportRegistry.
42 43 44 45 46 |
# File 'lib/lutaml/model/import_registry.rb', line 42 def initialize @pending_imports = {} @resolved_classes = Set.new @mutex = Mutex.new end |
Instance Attribute Details
#pending_imports ⇒ Hash<Class, Array<DeferredImport>> (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns Pending imports by owner class.
36 37 38 |
# File 'lib/lutaml/model/import_registry.rb', line 36 def pending_imports @pending_imports end |
#resolved_classes ⇒ Set<Class> (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns Classes whose imports have been resolved.
39 40 41 |
# File 'lib/lutaml/model/import_registry.rb', line 39 def resolved_classes @resolved_classes end |
Instance Method Details
#defer(owner_class, method:, symbol:) ⇒ DeferredImport
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Defer an import for later resolution.
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/lutaml/model/import_registry.rb', line 54 def defer(owner_class, method:, symbol:) import = DeferredImport.new( owner_class: owner_class, method: method, symbol: symbol, resolved: false, ) @mutex.synchronize do @pending_imports[owner_class] ||= [] @pending_imports[owner_class] << import # Mark as not resolved if we're adding new imports @resolved_classes.delete(owner_class) end import end |
#imports_for(owner_class) ⇒ Array<DeferredImport>
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Get pending imports for a class.
182 183 184 185 186 |
# File 'lib/lutaml/model/import_registry.rb', line 182 def imports_for(owner_class) @mutex.synchronize do @pending_imports[owner_class] || [] end end |
#pending?(owner_class) ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Check if a class has pending (unresolved) imports.
144 145 146 147 148 |
# File 'lib/lutaml/model/import_registry.rb', line 144 def pending?(owner_class) @mutex.synchronize do pending_without_lock?(owner_class) end end |
#pending_classes ⇒ Array<Class>
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Get all classes with pending imports.
191 192 193 194 195 |
# File 'lib/lutaml/model/import_registry.rb', line 191 def pending_classes @mutex.synchronize do @pending_imports.keys.select { |k| pending_without_lock?(k) } end end |
#reset! ⇒ void
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
This method returns an undefined value.
Reset all state (for testing).
200 201 202 203 204 205 |
# File 'lib/lutaml/model/import_registry.rb', line 200 def reset! @mutex.synchronize do @pending_imports.clear @resolved_classes.clear end end |
#resolve(owner_class, context) ⇒ Array<DeferredImport>
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Resolve all imports for a specific class.
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 |
# File 'lib/lutaml/model/import_registry.rb', line 78 def resolve(owner_class, context) return [] unless pending?(owner_class) resolved = [] @mutex.synchronize do imports = @pending_imports[owner_class] || [] imports.each do |import| next if import.resolved? # Resolve the type resolved_type = TypeResolver.resolve(import.symbol, context) # Store the resolved type on the owner class's attribute apply_resolution(owner_class, import.method, resolved_type) import.resolved = true resolved << import end @resolved_classes << owner_class end resolved end |
#resolve_all!(context) ⇒ Integer
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Resolve all pending imports.
108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 |
# File 'lib/lutaml/model/import_registry.rb', line 108 def resolve_all!(context) resolved_count = 0 @mutex.synchronize do @pending_imports.each_key do |owner_class| next if @resolved_classes.include?(owner_class) imports = @pending_imports[owner_class] || [] imports.each do |import| next if import.resolved? begin resolved_type = TypeResolver.resolve(import.symbol, context) apply_resolution(owner_class, import.method, resolved_type) import.resolved = true resolved_count += 1 rescue UnknownTypeError # Skip types that can't be resolved yet # They may be resolved in a later pass or by another context end end # Check if all imports for this class are resolved if imports.all?(&:resolved?) @resolved_classes << owner_class end end end resolved_count end |
#resolved?(owner_class) ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Check if a class’s imports are fully resolved.
169 170 171 172 173 174 175 176 |
# File 'lib/lutaml/model/import_registry.rb', line 169 def resolved?(owner_class) @mutex.synchronize do return true unless @pending_imports.key?(owner_class) return false unless @resolved_classes.include?(owner_class) @pending_imports[owner_class].all?(&:resolved?) end end |
#stats ⇒ Hash
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Get statistics about the registry.
210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 |
# File 'lib/lutaml/model/import_registry.rb', line 210 def stats @mutex.synchronize do total = @pending_imports.values.sum(&:size) resolved = @pending_imports.values.sum do |imports| imports.count(&:resolved?) end pending_count = @pending_imports.keys.count do |k| pending_without_lock?(k) end { total_imports: total, resolved_imports: resolved, pending_imports: total - resolved, pending_classes: pending_count, } end end |