Module: Glossarist::V3::HyperedgeRegistry

Defined in:
lib/glossarist/v3/hyperedge_registry.rb

Overview

HyperedgeRegistry — single SSOT for hyperedge-class lookup by every external identifier (wire key, type tag, RDF type).

Auto-populates on class inheritance via AbstractHyperedge.inherited. Concrete leaves declare WIRE_KEY / TYPE_TAG / RDF_TYPE constants in a per-class metadata block; the registry reads them once at registration time.

Adding a new hyperedge type means declaring one leaf class with the metadata block. No edit to any other file (parser, serializer, validator, RDF emitter, RelationLoader) — they all iterate or resolve through this registry.

Constant Summary collapse

BY_WIRE_KEY =

rubocop:disable Style/MutableConstant — these MUST stay mutable; register() adds entries at load time.

{}
BY_TYPE_TAG =
{}
BY_RDF_TYPE =
{}
Mutex =

rubocop:enable Style/MutableConstant

::Mutex.new

Class Method Summary collapse

Class Method Details

.all_classesObject

Iterate every concrete leaf (use this in parser / serializer / loader to stay type-blind).



45
46
47
# File 'lib/glossarist/v3/hyperedge_registry.rb', line 45

def all_classes
  BY_TYPE_TAG.values.uniq
end

.for_rdf_type(rdf_type) ⇒ Object



57
58
59
# File 'lib/glossarist/v3/hyperedge_registry.rb', line 57

def for_rdf_type(rdf_type)
  BY_RDF_TYPE[rdf_type]
end

.for_type_tag(tag) ⇒ Object



53
54
55
# File 'lib/glossarist/v3/hyperedge_registry.rb', line 53

def for_type_tag(tag)
  BY_TYPE_TAG[tag]
end

.for_wire_key(key) ⇒ Object



49
50
51
# File 'lib/glossarist/v3/hyperedge_registry.rb', line 49

def for_wire_key(key)
  BY_WIRE_KEY[key]
end

.register(cls) ⇒ Object

Register a concrete hyperedge class. Idempotent.



29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/glossarist/v3/hyperedge_registry.rb', line 29

def register(cls)
  return if cls.nil? || cls.const_defined?(:WIRE_KEY) == false

  Mutex.synchronize do
    wire = cls::WIRE_KEY
    tag  = cls::TYPE_TAG
    rdf  = cls::RDF_TYPE

    BY_WIRE_KEY[wire] = cls unless wire.nil? || wire.empty?
    BY_TYPE_TAG[tag]  = cls unless tag.nil? || tag.empty?
    BY_RDF_TYPE[rdf]  = cls unless rdf.nil? || rdf.empty?
  end
end

.reset!Object

Reset (spec helper — never call from production code).



62
63
64
65
66
67
68
# File 'lib/glossarist/v3/hyperedge_registry.rb', line 62

def reset!
  Mutex.synchronize do
    BY_WIRE_KEY.clear
    BY_TYPE_TAG.clear
    BY_RDF_TYPE.clear
  end
end