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



43
44
45
# File 'lib/chemicalml/convention/registry.rb', line 43

def self.builtin_qnames
  load_cache.keys.sort
end

.detect_and_validate(document) ⇒ Object

Detect the convention from the document's root convention attribute and validate. Raises ArgumentError if the document declares no convention or an unknown one.

Raises:

  • (ArgumentError)


36
37
38
39
40
41
# File 'lib/chemicalml/convention/registry.rb', line 36

def self.detect_and_validate(document)
  qname = Convention::Detection.convention_of(document)
  raise ArgumentError, "document declares no convention attribute" unless qname

  validate_report(document, qname: qname)
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



47
48
49
# File 'lib/chemicalml/convention/registry.rb', line 47

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

.validate_report(document, qname:) ⇒ Object

Raises:

  • (ArgumentError)


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

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

  convention.validate_report(document)
end