Class: Lutaml::Model::ModelTreeImporter
- Inherits:
-
Object
- Object
- Lutaml::Model::ModelTreeImporter
- Defined in:
- lib/lutaml/model/register/model_tree_importer.rb
Overview
Imports an entire model tree into a register.
Recursively walks the attribute graph and registers all types. Optionally binds all types to a specific namespace.
Instance Attribute Summary collapse
-
#namespace_class ⇒ Class?
readonly
Optional namespace class for binding.
-
#register ⇒ Register
readonly
The register to import into.
-
#visited ⇒ Set<Class>
readonly
Set of visited classes to avoid cycles.
Instance Method Summary collapse
-
#import(root_class) ⇒ Array<Class>
Import a model tree starting from root_class.
-
#initialize(register, namespace_class: nil) ⇒ ModelTreeImporter
constructor
Create a new model tree importer.
Constructor Details
#initialize(register, namespace_class: nil) ⇒ ModelTreeImporter
Create a new model tree importer.
32 33 34 35 36 |
# File 'lib/lutaml/model/register/model_tree_importer.rb', line 32 def initialize(register, namespace_class: nil) @register = register @namespace_class = namespace_class @visited = Set.new end |
Instance Attribute Details
#namespace_class ⇒ Class? (readonly)
Returns Optional namespace class for binding.
21 22 23 |
# File 'lib/lutaml/model/register/model_tree_importer.rb', line 21 def namespace_class @namespace_class end |
#register ⇒ Register (readonly)
Returns The register to import into.
17 18 19 |
# File 'lib/lutaml/model/register/model_tree_importer.rb', line 17 def register @register end |
#visited ⇒ Set<Class> (readonly)
Returns Set of visited classes to avoid cycles.
25 26 27 |
# File 'lib/lutaml/model/register/model_tree_importer.rb', line 25 def visited @visited end |
Instance Method Details
#import(root_class) ⇒ Array<Class>
Import a model tree starting from root_class.
Recursively registers the root class and all nested attribute types.
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/model/register/model_tree_importer.rb', line 45 def import(root_class) return [] if @visited.include?(root_class) @visited << root_class registered = [] # Bind namespace if provided if @namespace_class @register.bind_namespace(@namespace_class) end # Register the root class @register.register_model(root_class) registered << root_class # Recursively register all attribute types if root_class.include?(Lutaml::Model::Serialize) || root_class.include?(Lutaml::Model::Serializable) root_class.attributes.each_value do |attribute| registered.concat(import_attribute_type(attribute)) end end registered end |