Module: Lutaml::UmlRepository::IndexBuilders::PackageIndex
- Included in:
- Lutaml::UmlRepository::IndexBuilder
- Defined in:
- lib/lutaml/uml_repository/index_builders/package_index.rb
Instance Method Summary collapse
-
#build_package_path(name, parent_path) ⇒ String
Build a package path from a package name and parent path.
-
#build_package_path_index ⇒ Object
Build the package path index.
-
#traverse_packages(packages, parent_path: nil) {|package, path| ... } ⇒ Object
Traverse packages recursively, yielding each package with its path.
Instance Method Details
#build_package_path(name, parent_path) ⇒ String
Build a package path from a package name and parent path
54 55 56 57 58 |
# File 'lib/lutaml/uml_repository/index_builders/package_index.rb', line 54 def build_package_path(name, parent_path) return name unless parent_path "#{parent_path}::#{name}" end |
#build_package_path_index ⇒ Object
Build the package path index
Creates a hash mapping package paths to Package objects:
"ModelRoot" => Package{},
"ModelRoot::i-UR" => Package{},
"ModelRoot::i-UR::urf" => Package{}
14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/lutaml/uml_repository/index_builders/package_index.rb', line 14 def build_package_path_index # Add root package if it exists if @document @package_paths[IndexBuilder::ROOT_PACKAGE_NAME] = @document end # Traverse all packages recursively traverse_packages(@document.packages, parent_path: IndexBuilder::ROOT_PACKAGE_NAME) do |package, path| @package_paths[path] = package @package_to_path[package.xmi_id] = path if package.xmi_id end end |
#traverse_packages(packages, parent_path: nil) {|package, path| ... } ⇒ Object
Traverse packages recursively, yielding each package with its path
34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/lutaml/uml_repository/index_builders/package_index.rb', line 34 def traverse_packages(packages, parent_path: nil, &block) return unless packages packages.each do |package| path = build_package_path(package.name, parent_path) yield package, path if block # Recursively traverse nested packages if package.packages traverse_packages(package.packages, parent_path: path, &block) end end end |