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



79
80
81
82
83
84
85
# File 'lib/lutaml/uml_repository/repository/loader.rb', line 79

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)


75
76
77
# File 'lib/lutaml/uml_repository/repository/loader.rb', line 75

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



49
50
51
52
53
54
55
56
57
# File 'lib/lutaml/uml_repository/repository/loader.rb', line 49

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:



64
65
66
67
68
69
70
71
72
73
# File 'lib/lutaml/uml_repository/repository/loader.rb', line 64

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



108
109
110
111
112
113
114
115
116
# File 'lib/lutaml/uml_repository/repository/loader.rb', line 108

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:



91
92
93
# File 'lib/lutaml/uml_repository/repository/loader.rb', line 91

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:



99
100
101
# File 'lib/lutaml/uml_repository/repository/loader.rb', line 99

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:



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

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:



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

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