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.

Examples:

Load from XMI

repo = Loader.from_xmi('model.xmi')

Load from LUR package

repo = Loader.from_package('model.lur')

Auto-detect format

repo = Loader.from_file('model.xmi')

Class Method Summary collapse

Class Method Details

.from_file(path) ⇒ Repository

Auto-detect file type and load appropriately.

Parameters:

  • path (String)

    Path to the file (.xmi or .lur)

Returns:

Raises:

  • (ArgumentError)

    If the file type is unknown



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.

Parameters:

  • xmi_path (String)

    Path to the XMI file

  • lur_path (String, nil) (defaults to: nil)

    Path to the LUR package

Returns:



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.

Parameters:

  • path (String)

    Path to the file (.xmi or .lur)

Returns:

Raises:

  • (ArgumentError)

    If the file type is unknown



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.

Parameters:

  • lur_path (String)

    Path to the .lur package file

Returns:



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.

Parameters:

  • lur_path (String)

    Path to the .lur package file

Returns:



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.

Parameters:

  • xmi_path (String)

    Path to the XMI file

  • options (Hash) (defaults to: {})

    Options for parsing

Returns:



27
28
29
30
31
# File 'lib/lutaml/uml_repository/repository/loader.rb', line 27

def self.from_xmi(xmi_path, options = {})
  document = Lutaml::Parser.parse([File.new(xmi_path)]).first
  indexes = IndexBuilder.build_all(document)
  new(document: document, indexes: indexes, options: options)
end

.from_xmi_lazy(xmi_path, _options = {}) ⇒ LazyRepository

Build a Repository from an XMI file with lazy index loading.

Parameters:

  • xmi_path (String)

    Path to the XMI file

  • options (Hash)

    Options for parsing

Returns:



38
39
40
41
# File 'lib/lutaml/uml_repository/repository/loader.rb', line 38

def self.from_xmi_lazy(xmi_path, _options = {})
  document = Lutaml::Parser.parse([File.new(xmi_path)]).first
  LazyRepository.new(document: document, lazy: true)
end