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

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

Overview

Base class for per-format registry generators (one Ruby file that declares autoloads + a self.register_all that registers every generated class with the model registry).

Subclasses customize the ERB skeleton (e.g., XSD adds import resolution phases) but inherit the shared module-wrap and autoload/registration emit methods.

Direct Known Subclasses

XmlCompiler::RegistryGenerator

Constant Summary collapse

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

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

    def self.register_all
      context = Lutaml::Model::GlobalContext.context(:<%= @register_id %>) ||
                Lutaml::Model::GlobalContext.create_context(id: :<%= @register_id %>)

  <%= registration_body %>
    end
  <%= module_closing -%>
TMPL

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(model_entries, options) ⇒ RegistryGenerator

model_entries is an Array of CompiledOutput::Entry with kind :model. options[:namespaces] is an Array of :namespace entries, autoloaded but never registered.



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

def initialize(model_entries, options)
  @classes = model_entries
  @namespaces = options[:namespaces] || []
  @module_namespace = options[:module_namespace]
  @register_id = options[:register_id] || :default
  @modules = @module_namespace&.split("::") || []
end

Class Method Details

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



32
33
34
# File 'lib/lutaml/model/schema/registry_generator.rb', line 32

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

Instance Method Details

#generateObject



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

def generate
  return nil unless @module_namespace

  template.result(binding)
end