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_attributes, #all_classes, #all_diagrams, #associations_index, #associations_of, #classes_in_package, #classes_index, #diagrams_index, #export_to_package, #find_attribute, #find_diagram, 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, #statistics, #validate
Methods included from Repository::Deprecated
#export, #find_associations, #find_children, #find_diagrams, #search_classes
Constructor Details
#initialize(document:, indexes: nil, lazy: true) ⇒ LazyRepository
Initialize a new LazyRepository with lazy index building.
31 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 |
# File 'lib/lutaml/uml_repository/lazy_repository.rb', line 31 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.
130 131 132 133 134 |
# File 'lib/lutaml/uml_repository/lazy_repository.rb', line 130 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.
170 171 172 173 |
# File 'lib/lutaml/uml_repository/lazy_repository.rb', line 170 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.
144 145 146 147 |
# File 'lib/lutaml/uml_repository/lazy_repository.rb', line 144 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.
155 156 157 158 |
# File 'lib/lutaml/uml_repository/lazy_repository.rb', line 155 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]
69 70 71 72 |
# File 'lib/lutaml/uml_repository/lazy_repository.rb', line 69 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.
92 93 94 95 |
# File 'lib/lutaml/uml_repository/lazy_repository.rb', line 92 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.
81 82 83 84 |
# File 'lib/lutaml/uml_repository/lazy_repository.rb', line 81 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.
183 184 185 |
# File 'lib/lutaml/uml_repository/lazy_repository.rb', line 183 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.
194 195 196 |
# File 'lib/lutaml/uml_repository/lazy_repository.rb', line 194 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.
118 119 120 121 |
# File 'lib/lutaml/uml_repository/lazy_repository.rb', line 118 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.
104 105 106 107 108 |
# File 'lib/lutaml/uml_repository/lazy_repository.rb', line 104 def supertype_of(class_or_qname) ensure_index(:qualified_names) ensure_index(:inheritance_graph) super end |