Module: Lutaml::UmlRepository::Repository::Loader
- Defined in:
- lib/lutaml/uml_repository/repository/loader.rb
Overview
Handles loading Repository instances from various file formats.
Encapsulates all file I/O and format detection logic, keeping the main Repository class focused on querying.
Class Method Summary collapse
-
.from_file(path) ⇒ Repository
Auto-detect file type and load appropriately.
-
.from_file_cached(xmi_path, lur_path: nil) ⇒ Repository
Smart caching - use LUR if newer than XMI, otherwise rebuild.
-
.from_file_lazy(path) ⇒ LazyRepository
Auto-detect file type with lazy loading.
-
.from_package(lur_path) ⇒ Repository
Load a Repository from a LUR package file.
-
.from_package_lazy(lur_path) ⇒ LazyRepository
Load a Repository from a LUR package with lazy loading.
-
.from_xmi(xmi_path, options = {}) ⇒ Repository
Build a Repository from an XMI file.
-
.from_xmi_lazy(xmi_path, _options = {}) ⇒ LazyRepository
Build a Repository from an XMI file with lazy index loading.
Class Method Details
.from_file(path) ⇒ Repository
Auto-detect file type and load appropriately.
48 49 50 51 52 53 54 55 56 |
# File 'lib/lutaml/uml_repository/repository/loader.rb', line 48 def self.from_file(path) case File.extname(path).downcase when ".xmi" then from_xmi(path) when ".lur" then from_package(path) else raise ArgumentError, "Unknown file type: #{path}. Expected .xmi or .lur" end end |
.from_file_cached(xmi_path, lur_path: nil) ⇒ Repository
Smart caching - use LUR if newer than XMI, otherwise rebuild.
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/lutaml/uml_repository/repository/loader.rb', line 63 def self.from_file_cached(xmi_path, lur_path: nil) lur_path ||= xmi_path.sub(/\.xmi$/i, ".lur") if File.exist?(lur_path) && File.mtime(lur_path) >= File.mtime(xmi_path) puts "Using cached LUR package: #{lur_path}" if $VERBOSE from_package(lur_path) else puts "Building repository from XMI..." if $VERBOSE repo = from_xmi(xmi_path) puts "Caching as LUR package: #{lur_path}" if $VERBOSE repo.export_to_package(lur_path) repo end end |
.from_file_lazy(path) ⇒ LazyRepository
Auto-detect file type with lazy loading.
100 101 102 103 104 105 106 107 108 |
# File 'lib/lutaml/uml_repository/repository/loader.rb', line 100 def self.from_file_lazy(path) case File.extname(path).downcase when ".xmi" then from_xmi_lazy(path) when ".lur" then from_package_lazy(path) else raise ArgumentError, "Unknown file type: #{path}. Expected .xmi or .lur" end end |
.from_package(lur_path) ⇒ Repository
Load a Repository from a LUR package file.
83 84 85 |
# File 'lib/lutaml/uml_repository/repository/loader.rb', line 83 def self.from_package(lur_path) PackageLoader.load(lur_path) end |
.from_package_lazy(lur_path) ⇒ LazyRepository
Load a Repository from a LUR package with lazy loading.
91 92 93 |
# File 'lib/lutaml/uml_repository/repository/loader.rb', line 91 def self.from_package_lazy(lur_path) PackageLoader.load_document_only(lur_path) end |
.from_xmi(xmi_path, options = {}) ⇒ Repository
Build a Repository from an XMI file.
27 28 29 30 31 |
# File 'lib/lutaml/uml_repository/repository/loader.rb', line 27 def self.from_xmi(xmi_path, = {}) document = Lutaml::Parser.parse([File.new(xmi_path)]).first indexes = IndexBuilder.build_all(document) new(document: document, indexes: indexes, options: ) end |
.from_xmi_lazy(xmi_path, _options = {}) ⇒ LazyRepository
Build a Repository from an XMI file with lazy index loading.
38 39 40 41 |
# File 'lib/lutaml/uml_repository/repository/loader.rb', line 38 def self.from_xmi_lazy(xmi_path, = {}) document = Lutaml::Parser.parse([File.new(xmi_path)]).first LazyRepository.new(document: document, lazy: true) end |