Class: Lutaml::UmlRepository::PackageLoader

Inherits:
Object
  • Object
show all
Defined in:
lib/lutaml/uml_repository/package_loader.rb

Overview

PackageLoader handles loading UmlRepository instances from LUR (LutaML UML Repository) package files.

LUR packages are ZIP archives that contain pre-serialized repositories for fast loading without re-parsing XMI files.

Examples:

Load from package

repository = PackageLoader.load("model.lur")
klass = repository.find_class("ModelRoot::MyClass")

Class Method Summary collapse

Class Method Details

.load(lur_path) ⇒ UmlRepository

Load a UmlRepository from a LUR package file.

Examples:

repo = PackageLoader.load("model.lur")

Parameters:

  • lur_path (String)

    Path to the .lur package file

Returns:

Raises:

  • (ArgumentError)

    If the package file doesn’t exist

  • (RuntimeError)

    If the package is invalid or corrupted



28
29
30
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
# File 'lib/lutaml/uml_repository/package_loader.rb', line 28

def self.load(lur_path) # rubocop:disable Metrics/MethodLength
  unless File.exist?(lur_path)
    raise ArgumentError, "Package file not found: #{lur_path}"
  end

  document = nil
  indexes = nil
   = nil

  begin
    Zip::File.open(lur_path) do |zip|
      # Read metadata (now returns PackageMetadata)
       = (zip)

      # Load Document based on format
      document = load_document(zip, )

      # Load indexes
      indexes = load_indexes(zip)
    end
  rescue Zip::Error => e
    raise "Invalid LUR package: #{e.message}"
  rescue StandardError => e
    raise "Failed to load package: #{e.message}"
  end

  # Create repository with loaded data and metadata
  Repository.new(document: document, indexes: indexes, metadata: )
end

.load_document_only(lur_path) ⇒ LazyRepository

Load only the document from a LUR package without building indexes.

This method loads the document but does not load or build indexes, returning a LazyRepository instance that will build indexes on-demand.

Examples:

repo = PackageLoader.load_document_only("model.lur")

Parameters:

  • lur_path (String)

    Path to the .lur package file

Returns:

Raises:

  • (ArgumentError)

    If the package file doesn’t exist

  • (RuntimeError)

    If the package is invalid or corrupted



69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# File 'lib/lutaml/uml_repository/package_loader.rb', line 69

def self.load_document_only(lur_path) # rubocop:disable Metrics/MethodLength
  unless File.exist?(lur_path)
    raise ArgumentError, "Package file not found: #{lur_path}"
  end

  document = nil
   = nil

  begin
    Zip::File.open(lur_path) do |zip|
      # Read metadata (now returns PackageMetadata)
       = (zip)

      # Load Document based on format
      document = load_document(zip, )
    end
  rescue Zip::Error => e
    raise "Invalid LUR package: #{e.message}"
  rescue StandardError => e
    raise "Failed to load package: #{e.message}"
  end

  # Create lazy repository without indexes but with metadata
  require_relative "../lazy_repository"
  LazyRepository.new(document: document, lazy: true, metadata: )
end