Module: Newsmlg2::Configuration

Defined in:
lib/newsmlg2/configuration.rb

Overview

Registry of the NewsML-G2 root models in a lutaml-model global context, keyed by element id. This is the single source of truth for element-name → class resolution (root dispatch, itemSet items) — following the plurimath/mml pattern, library code never compares element-name strings itself.

Constant Summary collapse

CONTEXT_ID =
:newsmlg2

Class Method Summary collapse

Class Method Details

.contextObject



13
14
15
# File 'lib/newsmlg2/configuration.rb', line 13

def context
  Lutaml::Model::GlobalContext.context(CONTEXT_ID)
end

.populate_context!Object

Rebuilds the built-in context from the registered models.



18
19
20
21
22
23
24
25
26
27
28
# File 'lib/newsmlg2/configuration.rb', line 18

def populate_context!
  Lutaml::Model::GlobalContext.unregister_context(CONTEXT_ID) if context
  type_context = Lutaml::Model::GlobalContext.create_context(
    id: CONTEXT_ID,
    registry: Lutaml::Model::TypeRegistry.new,
    fallback_to: [:default]
  )
  register_models_in(type_context)
  Lutaml::Model::GlobalContext.clear_caches
  type_context
end

.register_model(klass, id:) ⇒ Object

Registers a model under its element id (see the registration block at the bottom of lib/newsmlg2.rb).



32
33
34
35
36
37
# File 'lib/newsmlg2/configuration.rb', line 32

def register_model(klass, id:)
  normalized_id = id.to_sym
  registered_models[normalized_id] = klass
  (context || populate_context!).registry.register(normalized_id, klass)
  klass
end

.resolve(element_name) ⇒ Object

Resolves an element name to its registered model class, or nil for unregistered names (non-element nodes, foreign roots).



41
42
43
44
45
46
# File 'lib/newsmlg2/configuration.rb', line 41

def resolve(element_name)
  name = element_name.to_sym
  return nil unless Lutaml::Model::GlobalContext.resolvable?(name, CONTEXT_ID)

  Lutaml::Model::GlobalContext.resolve_type(name, CONTEXT_ID)
end