Class: Lutaml::UmlRepository::LazyRepository
- Inherits:
-
Repository
- Object
- Repository
- Lutaml::UmlRepository::LazyRepository
- Defined in:
- lib/lutaml/uml_repository/lazy_repository.rb
Overview
LazyRepository provides lazy loading optimization for very large UML models
For extremely large models (1000+ classes), LazyRepository optimizes memory usage and initial load time by building indexes on-demand rather than upfront. Indexes are built only when first accessed, reducing the initial load time significantly.
Instance Attribute Summary
Attributes inherited from Repository
#document, #indexes, #metadata
Instance Method Summary collapse
-
#ancestors_of(class_or_qname) ⇒ Array
Get all ancestor classes up to the root.
-
#build_all_indexes ⇒ LazyRepository
Manually build all remaining indexes.
-
#descendants_of(class_or_qname, max_depth: nil) ⇒ Array
Get all descendant classes.
-
#diagrams_in_package(package_path) ⇒ Array<Lutaml::Uml::Diagram>
Get diagrams in a specific package.
-
#find_class(qualified_name, raise_on_error: false) ⇒ Lutaml::Uml::Class, ...
Find a class by its qualified name.
-
#find_classes_by_stereotype(stereotype) ⇒ Array
Find all classes with a specific stereotype.
-
#find_package(path, raise_on_error: false) ⇒ Lutaml::Uml::Package, ...
Find a package by its path.
-
#index_built?(index_name) ⇒ Boolean
Check if an index is built.
-
#initialize(document:, indexes: nil, lazy: true) ⇒ LazyRepository
constructor
Initialize a new LazyRepository with lazy index building.
-
#pending_indexes ⇒ Array<Symbol>
Get list of pending indexes.
-
#subtypes_of(class_or_qname, recursive: false) ⇒ Array
Get direct child classes (subtypes).
-
#supertype_of(class_or_qname) ⇒ Lutaml::Uml::Class?
Get the direct parent class (supertype).
Methods inherited from Repository
#all_classes, #all_diagrams, #associations_index, #associations_of, #classes_in_package, #classes_index, #diagrams_index, #export, #export_to_package, #find_associations, #find_children, #find_diagram, #find_diagrams, from_file, from_file_cached, from_file_lazy, from_package, from_package_lazy, from_xmi, from_xmi_lazy, #list_packages, #marshal_dump, #marshal_load, #package_tree, #packages_index, #qualified_name_for, #query, #query!, #search, #search_classes, #statistics, #validate
Constructor Details
#initialize(document:, indexes: nil, lazy: true) ⇒ LazyRepository
Initialize a new LazyRepository with lazy index building.
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 |
# File 'lib/lutaml/uml_repository/lazy_repository.rb', line 33 def initialize(document:, indexes: nil, lazy: true) # rubocop:disable Metrics/AbcSize,Metrics/MethodLength @document = document @indexes = indexes || {} @lazy_mode = lazy @index_builders_pending = Set.new(%i[ package_paths qualified_names stereotypes inheritance_graph diagram_index ]) # Initialize runtime query services (not serialized to LUR) # These are lightweight wrappers that operate on @document and @indexes @package_query = Queries::PackageQuery.new(@document, @indexes) @class_query = Queries::ClassQuery.new(@document, @indexes) @inheritance_query = Queries::InheritanceQuery.new(@document, @indexes) @association_query = Queries::AssociationQuery.new(@document, @indexes) @diagram_query = Queries::DiagramQuery.new(@document, @indexes) @search_query = Queries::SearchQuery.new(@document, @indexes) # Initialize statistics calculator (lazily computed) @statistics_calculator = StatisticsCalculator.new(@document, @indexes) # Initialize error handler for helpful error messages @error_handler = ErrorHandler.new(self) # Don't freeze - we build indexes on demand end |
Instance Method Details
#ancestors_of(class_or_qname) ⇒ Array
Get all ancestor classes up to the root.
Ensures the qualified_names and inheritance_graph indexes are built.
132 133 134 135 136 |
# File 'lib/lutaml/uml_repository/lazy_repository.rb', line 132 def ancestors_of(class_or_qname) ensure_index(:qualified_names) ensure_index(:inheritance_graph) super end |
#build_all_indexes ⇒ LazyRepository
Manually build all remaining indexes.
This method can be called to force building all indexes at once, rather than waiting for them to be built on-demand.
172 173 174 175 |
# File 'lib/lutaml/uml_repository/lazy_repository.rb', line 172 def build_all_indexes @index_builders_pending.each { |index_name| ensure_index(index_name) } self end |
#descendants_of(class_or_qname, max_depth: nil) ⇒ Array
Get all descendant classes.
Ensures the inheritance_graph index is built before querying.
146 147 148 149 |
# File 'lib/lutaml/uml_repository/lazy_repository.rb', line 146 def descendants_of(class_or_qname, max_depth: nil) ensure_index(:inheritance_graph) super end |
#diagrams_in_package(package_path) ⇒ Array<Lutaml::Uml::Diagram>
Get diagrams in a specific package.
Ensures the diagram_index is built before querying.
157 158 159 160 |
# File 'lib/lutaml/uml_repository/lazy_repository.rb', line 157 def diagrams_in_package(package_path) ensure_index(:diagram_index) super end |
#find_class(qualified_name, raise_on_error: false) ⇒ Lutaml::Uml::Class, ...
Find a class by its qualified name.
Ensures the qualified_names index is built before querying.
Lutaml::Uml::Enum, nil]
71 72 73 74 |
# File 'lib/lutaml/uml_repository/lazy_repository.rb', line 71 def find_class(qualified_name, raise_on_error: false) ensure_index(:qualified_names) super end |
#find_classes_by_stereotype(stereotype) ⇒ Array
Find all classes with a specific stereotype.
Ensures the stereotypes index is built before querying.
94 95 96 97 |
# File 'lib/lutaml/uml_repository/lazy_repository.rb', line 94 def find_classes_by_stereotype(stereotype) ensure_index(:stereotypes) super end |
#find_package(path, raise_on_error: false) ⇒ Lutaml::Uml::Package, ...
Find a package by its path.
Ensures the package_paths index is built before querying.
83 84 85 86 |
# File 'lib/lutaml/uml_repository/lazy_repository.rb', line 83 def find_package(path, raise_on_error: false) ensure_index(:package_paths) super end |
#index_built?(index_name) ⇒ Boolean
Check if an index is built.
185 186 187 |
# File 'lib/lutaml/uml_repository/lazy_repository.rb', line 185 def index_built?(index_name) @indexes.key?(index_name) && !@indexes[index_name].nil? end |
#pending_indexes ⇒ Array<Symbol>
Get list of pending indexes.
Returns the names of indexes that have not yet been built.
196 197 198 |
# File 'lib/lutaml/uml_repository/lazy_repository.rb', line 196 def pending_indexes @index_builders_pending.to_a end |
#subtypes_of(class_or_qname, recursive: false) ⇒ Array
Get direct child classes (subtypes).
Ensures the inheritance_graph index is built before querying.
120 121 122 123 |
# File 'lib/lutaml/uml_repository/lazy_repository.rb', line 120 def subtypes_of(class_or_qname, recursive: false) ensure_index(:inheritance_graph) super end |
#supertype_of(class_or_qname) ⇒ Lutaml::Uml::Class?
Get the direct parent class (supertype).
Ensures the qualified_names and inheritance_graph indexes are built.
106 107 108 109 110 |
# File 'lib/lutaml/uml_repository/lazy_repository.rb', line 106 def supertype_of(class_or_qname) ensure_index(:qualified_names) ensure_index(:inheritance_graph) super end |