Class: Lutaml::Model::Schema::ClassLoader

Inherits:
Object
  • Object
show all
Defined in:
lib/lutaml/model/schema/class_loader.rb

Overview

Writes a CompiledOutput to a temporary directory, requires the registry, and runs register_all so the generated classes are loaded into a real module the caller can use immediately. Shared between XSD and RNG compilers.

Constant Summary collapse

DEFAULT_NAMESPACE =
"GeneratedModels"

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(output, registry_generator) ⇒ ClassLoader

Returns a new instance of ClassLoader.



22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/lutaml/model/schema/class_loader.rb', line 22

def initialize(output, registry_generator)
  # ClassLoader needs a module to host the registry constant
  # (so `register_all` has a home). If the caller wanted
  # unwrapped class files, we still force a registry module —
  # but we pin `source_module_namespace` to what they asked for,
  # so per-class files keep their original wrapping.
  @output = CompiledOutput.new(
    entries: output.entries,
    module_namespace: output.module_namespace || DEFAULT_NAMESPACE,
    register_id: output.register_id,
    source_module_namespace: output.module_namespace,
  )
  @registry_generator = registry_generator
end

Class Method Details

.load(output, registry_generator: RegistryGenerator) ⇒ Object



18
19
20
# File 'lib/lutaml/model/schema/class_loader.rb', line 18

def self.load(output, registry_generator: RegistryGenerator)
  new(output, registry_generator).load
end

Instance Method Details

#loadObject



37
38
39
40
41
42
43
# File 'lib/lutaml/model/schema/class_loader.rb', line 37

def load
  Dir.mktmpdir do |dir|
    FileWriter.write(@output, dir, registry_generator: @registry_generator)
    require File.join(dir, "#{registry_basename}_registry")
    call_register_all
  end
end