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

.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

Returns:

  • (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.

Parameters:

  • path (String)

    Path to the file (.xmi or .lur)

Returns:

Raises:

  • (ArgumentError)

    If the file type is unknown



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.

Parameters:

  • xmi_path (String)

    Path to the XMI file

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

    Path to the LUR package

Returns:



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.

Parameters:

  • path (String)

    Path to the file (.xmi or .lur)

Returns:

Raises:

  • (ArgumentError)

    If the file type is unknown



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.

Parameters:

  • lur_path (String)

    Path to the .lur package file

Returns:



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.

Parameters:

  • lur_path (String)

    Path to the .lur package file

Returns:



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.

Parameters:

  • xmi_path (String)

    Path to the XMI file

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

    Options for parsing

Returns:



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

def self.from_xmi(xmi_path, options = {})
  document = Lutaml::Xmi::Parsers::Xml.parse(File.new(xmi_path))
  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:



36
37
38
39
# File 'lib/lutaml/uml_repository/repository/loader.rb', line 36

def self.from_xmi_lazy(xmi_path, _options = {})
  document = Lutaml::Xmi::Parsers::Xml.parse(File.new(xmi_path))
  LazyRepository.new(document: document, lazy: true)
end