Class: Lutaml::Model::Schema::XmlCompiler::RegistryGenerator

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

Constant Summary collapse

TEMPLATE =
ERB.new(<<~TEMPLATE, trim_mode: "-")
  # frozen_string_literal: true
  # Auto-generated central registry for <%= @module_namespace %>

  <%= module_opening %>
  <%= autoload_declarations %>

    def self.register_all
      # Ensure context exists before using it
      context = Lutaml::Model::GlobalContext.context(:<%= @register_id %>) ||
                Lutaml::Model::GlobalContext.create_context(id: :<%= @register_id %>)

      # Phase 1: Register all models (no imports)
  <%= registration_calls %>

      # Phase 2: Resolve model, choice, and restrict imports
  <%= model_import_resolution_calls %>

      # Phase 3: Resolve mapping and sequence imports
  <%= mapping_import_resolution_calls %>
    end
  <%= module_closing %>
TEMPLATE

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(classes_hash, options) ⇒ RegistryGenerator

Returns a new instance of RegistryGenerator.



38
39
40
41
42
43
44
# File 'lib/lutaml/model/schema/xml_compiler/registry_generator.rb', line 38

def initialize(classes_hash, options)
  @classes = classes_hash
  @module_namespace = options[:module_namespace]
  @register_id = options[:register_id] || :default
  # Cache split modules for reuse
  @modules = @module_namespace&.split("::") || []
end

Class Method Details

.generate(classes_hash, options = {}) ⇒ Object



34
35
36
# File 'lib/lutaml/model/schema/xml_compiler/registry_generator.rb', line 34

def self.generate(classes_hash, options = {})
  new(classes_hash, options).generate
end

Instance Method Details

#generateObject



46
47
48
49
50
# File 'lib/lutaml/model/schema/xml_compiler/registry_generator.rb', line 46

def generate
  return nil unless @module_namespace

  TEMPLATE.result(binding)
end