Class: Metanorma::Mirror::ClassTable
- Inherits:
-
Object
- Object
- Metanorma::Mirror::ClassTable
- Defined in:
- lib/metanorma/mirror/class_table.rb
Overview
A class-keyed lookup with ancestor fallback, in registration order. Consumers register their own model classes to payloads (lambdas, strings, prefixes); the table — and therefore this gem — carries no model knowledge. The metanorma-document and metanorma-standoc seeds register their classes at load time.
Instance Method Summary collapse
- #empty? ⇒ Boolean
-
#initialize ⇒ ClassTable
constructor
A new instance of ClassTable.
- #lookup(instance) ⇒ Object
- #register(klass, payload) ⇒ Object
- #registered?(klass) ⇒ Boolean
Constructor Details
#initialize ⇒ ClassTable
Returns a new instance of ClassTable.
11 12 13 |
# File 'lib/metanorma/mirror/class_table.rb', line 11 def initialize @entries = {} end |
Instance Method Details
#empty? ⇒ Boolean
28 29 30 |
# File 'lib/metanorma/mirror/class_table.rb', line 28 def empty? @entries.empty? end |
#lookup(instance) ⇒ Object
20 21 22 |
# File 'lib/metanorma/mirror/class_table.rb', line 20 def lookup(instance) entry_for(instance.class) || ancestor_entry(instance.class) end |
#register(klass, payload) ⇒ Object
15 16 17 18 |
# File 'lib/metanorma/mirror/class_table.rb', line 15 def register(klass, payload) @entries[klass] = payload self end |
#registered?(klass) ⇒ Boolean
24 25 26 |
# File 'lib/metanorma/mirror/class_table.rb', line 24 def registered?(klass) @entries.key?(klass) end |