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
- .build_and_cache(xmi_path, lur_path) ⇒ Object
- .cache_valid?(lur_path, xmi_path) ⇒ Boolean
-
.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
.build_and_cache(xmi_path, lur_path) ⇒ Object
76 77 78 79 80 81 82 |
# File 'lib/lutaml/uml_repository/repository/loader.rb', line 76 def self.build_and_cache(xmi_path, lur_path) 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 |
.cache_valid?(lur_path, xmi_path) ⇒ Boolean
72 73 74 |
# File 'lib/lutaml/uml_repository/repository/loader.rb', line 72 def self.cache_valid?(lur_path, xmi_path) File.exist?(lur_path) && File.mtime(lur_path) >= File.mtime(xmi_path) end |
.from_file(path) ⇒ Repository
Auto-detect file type and load appropriately.
46 47 48 49 50 51 52 53 54 |
# File 'lib/lutaml/uml_repository/repository/loader.rb', line 46 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.
61 62 63 64 65 66 67 68 69 70 |
# File 'lib/lutaml/uml_repository/repository/loader.rb', line 61 def self.from_file_cached(xmi_path, lur_path: nil) lur_path ||= xmi_path.sub(/\.xmi$/i, ".lur") if cache_valid?(lur_path, xmi_path) puts "Using cached LUR package: #{lur_path}" if $VERBOSE from_package(lur_path) else build_and_cache(xmi_path, lur_path) end end |
.from_file_lazy(path) ⇒ LazyRepository
Auto-detect file type with lazy loading.
105 106 107 108 109 110 111 112 113 |
# File 'lib/lutaml/uml_repository/repository/loader.rb', line 105 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.
88 89 90 |
# File 'lib/lutaml/uml_repository/repository/loader.rb', line 88 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.
96 97 98 |
# File 'lib/lutaml/uml_repository/repository/loader.rb', line 96 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.
25 26 27 28 29 |
# File 'lib/lutaml/uml_repository/repository/loader.rb', line 25 def self.from_xmi(xmi_path, = {}) document = Lutaml::Xmi::Parsers::Xml.parse(File.new(xmi_path)) 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.
36 37 38 39 |
# File 'lib/lutaml/uml_repository/repository/loader.rb', line 36 def self.from_xmi_lazy(xmi_path, = {}) document = Lutaml::Xmi::Parsers::Xml.parse(File.new(xmi_path)) LazyRepository.new(document: document, lazy: true) end |