Module: Chemicalml::Convention::Registry

Defined in:
lib/chemicalml/convention/registry.rb

Overview

Lookup table for conventions. Built-in conventions are registered lazily on first access to avoid load-order surprises.

Adding a new convention = creating a subclass of Base that returns its QName and namespace_uri, then registering it here. No switch statements, no if/elsif chains in framework code.

Class Method Summary collapse

Class Method Details

.builtin_qnamesObject



26
27
28
# File 'lib/chemicalml/convention/registry.rb', line 26

def self.builtin_qnames
  load_cache.keys.sort
end

.lookup(qname) ⇒ Object



15
16
17
# File 'lib/chemicalml/convention/registry.rb', line 15

def self.lookup(qname)
  load_cache[qname.to_s]
end

.reset!Object



30
31
32
# File 'lib/chemicalml/convention/registry.rb', line 30

def self.reset!
  @mutex.synchronize { @cache = nil }
end

.validate(document, qname:) ⇒ Object

Raises:

  • (ArgumentError)


19
20
21
22
23
24
# File 'lib/chemicalml/convention/registry.rb', line 19

def self.validate(document, qname:)
  convention = lookup(qname)
  raise ArgumentError, "unknown convention: #{qname.inspect}" unless convention

  convention.validate(document)
end