Module: Lutaml::Cli::Uml::SharedHelpers
- Included in:
- FindCommand, InspectCommand, LsCommand, SearchCommand, StatsCommand, TreeCommand
- Defined in:
- lib/lutaml/cli/uml/shared_helpers.rb
Overview
SharedHelpers provides common utility methods for UML commands
This module is included in command classes to provide shared functionality like repository loading and path normalization, following the DRY principle.
Instance Method Summary collapse
-
#load_repository(lur_path, lazy: false) ⇒ Lutaml::UmlRepository::Repository
Load repository from LUR file.
-
#normalize_path(path) ⇒ String
Normalize path syntax.
Instance Method Details
#load_repository(lur_path, lazy: false) ⇒ Lutaml::UmlRepository::Repository
Load repository from LUR file
20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/lutaml/cli/uml/shared_helpers.rb', line 20 def load_repository(lur_path, lazy: false) # rubocop:disable Metrics/MethodLength OutputFormatter.progress("Loading repository from #{lur_path}") repo = if lazy Lutaml::UmlRepository::Repository.from_package_lazy(lur_path) else Lutaml::UmlRepository::Repository.from_package(lur_path) end OutputFormatter.progress_done repo rescue StandardError => e OutputFormatter.progress_done(success: false) puts OutputFormatter.error("Failed to load repository: #{e.}") raise Thor::Error, e. end |
#normalize_path(path) ⇒ String
Normalize path syntax
- Converts
- or <RepositoryRoot>
-
to ModelRoot
41 42 43 44 45 46 47 |
# File 'lib/lutaml/cli/uml/shared_helpers.rb', line 41 def normalize_path(path) return "ModelRoot" if path.nil? || path.empty? return "ModelRoot" if ["::", "<RepositoryRoot>"].include?(path) path = path.sub(/^::/, "ModelRoot::") path.sub(/^<RepositoryRoot>::/, "ModelRoot::") end |