Class: Lutaml::Model::TypeRegistry Private
- Inherits:
-
Object
- Object
- Lutaml::Model::TypeRegistry
- Defined in:
- lib/lutaml/model/type_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.
TypeRegistry is a pure data store for type mappings.
This is an INTERNAL class. Users should use Register and GlobalRegister.
Responsibility: Store and retrieve type mappings (Symbol => Class)
This class has NO knowledge of:
-
Type resolution logic (see TypeResolver)
-
Type substitution (see TypeSubstitution)
-
Fallback chains (see TypeContext)
-
Caching (see CachedTypeResolver)
Instance Attribute Summary collapse
- #types ⇒ Object readonly private
Instance Method Summary collapse
-
#clear ⇒ Hash
private
Clear all registered types.
-
#dup ⇒ TypeRegistry
private
Create a copy of this registry.
-
#each {|Symbol, Class| ... } ⇒ Enumerator
private
Iterate over all registered types.
-
#empty? ⇒ Boolean
private
Check if the registry is empty.
-
#initialize ⇒ TypeRegistry
constructor
private
Initialize a new empty TypeRegistry.
-
#lookup(name) ⇒ Class?
private
Look up a type class by name.
-
#merge(other) ⇒ TypeRegistry
private
Create a new registry by merging this one with another.
-
#merge!(other) ⇒ TypeRegistry
private
Merge another registry into this one.
-
#names ⇒ Array<Symbol>
private
Get all registered type names.
-
#register(name, klass) ⇒ Class, Proc
private
Register a type class with a given name.
-
#registered?(name) ⇒ Boolean
private
Check if a type is registered.
-
#size ⇒ Integer
private
Get the number of registered types.
Constructor Details
#initialize ⇒ TypeRegistry
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.
Initialize a new empty TypeRegistry
32 33 34 |
# File 'lib/lutaml/model/type_registry.rb', line 32 def initialize @types = {} end |
Instance Attribute Details
#types ⇒ Object (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.
29 30 31 |
# File 'lib/lutaml/model/type_registry.rb', line 29 def types @types end |
Instance Method Details
#clear ⇒ 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.
Clear all registered types
This is primarily useful for testing to ensure isolation.
105 106 107 |
# File 'lib/lutaml/model/type_registry.rb', line 105 def clear @types.clear end |
#dup ⇒ TypeRegistry
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 copy of this registry
137 138 139 140 141 142 143 |
# File 'lib/lutaml/model/type_registry.rb', line 137 def dup new_registry = self.class.new @types.each do |name, klass| new_registry.register(name, klass) end new_registry end |
#each {|Symbol, Class| ... } ⇒ Enumerator
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.
Iterate over all registered types
130 131 132 |
# File 'lib/lutaml/model/type_registry.rb', line 130 def each(&) @types.each(&) end |
#empty? ⇒ 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 the registry is empty
112 113 114 |
# File 'lib/lutaml/model/type_registry.rb', line 112 def empty? @types.empty? end |
#lookup(name) ⇒ 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.
Look up a type class by name. If the type was registered as a Proc (lazy registration), the Proc is called and the result is cached.
62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/lutaml/model/type_registry.rb', line 62 def lookup(name) key = name.to_sym value = @types[key] if value.is_a?(Proc) resolved = value.call @types[key] = resolved resolved else value end end |
#merge(other) ⇒ TypeRegistry
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 registry by merging this one with another
160 161 162 |
# File 'lib/lutaml/model/type_registry.rb', line 160 def merge(other) dup.merge!(other) end |
#merge!(other) ⇒ TypeRegistry
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.
Merge another registry into this one
149 150 151 152 153 154 |
# File 'lib/lutaml/model/type_registry.rb', line 149 def merge!(other) other.types.each do |name, klass| register(name, klass) unless registered?(name) end self end |
#names ⇒ Array<Symbol>
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 registered type names
93 94 95 |
# File 'lib/lutaml/model/type_registry.rb', line 93 def names @types.keys end |
#register(name, klass) ⇒ Class, Proc
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.
Register a type class with a given name. Accepts a Class for eager registration or a Proc for lazy registration.
49 50 51 |
# File 'lib/lutaml/model/type_registry.rb', line 49 def register(name, klass) @types[name.to_sym] = klass end |
#registered?(name) ⇒ 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 type is registered
83 84 85 |
# File 'lib/lutaml/model/type_registry.rb', line 83 def registered?(name) @types.key?(name.to_sym) end |
#size ⇒ 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.
Get the number of registered types
119 120 121 |
# File 'lib/lutaml/model/type_registry.rb', line 119 def size @types.size end |