Class: Tdc::ExtendedAttributes::InterpreterRegistry
- Inherits:
-
Object
- Object
- Tdc::ExtendedAttributes::InterpreterRegistry
- Includes:
- Singleton
- Defined in:
- lib/tdc/extended_attributes/interpreter_registry.rb
Overview
Knows the class instances that interpret extended attribute values.
Class Method Summary collapse
Instance Method Summary collapse
- #clear ⇒ Object
-
#initialize ⇒ InterpreterRegistry
constructor
A new instance of InterpreterRegistry.
- #interpreters ⇒ Object
- #register_interpreter(interpreter) ⇒ Object
Constructor Details
#initialize ⇒ InterpreterRegistry
Returns a new instance of InterpreterRegistry.
15 16 17 |
# File 'lib/tdc/extended_attributes/interpreter_registry.rb', line 15 def initialize @interpreters = [] end |
Class Method Details
.register(interpreter:) ⇒ Object
11 12 13 |
# File 'lib/tdc/extended_attributes/interpreter_registry.rb', line 11 def self.register(interpreter:) instance.register_interpreter(interpreter) end |
Instance Method Details
#clear ⇒ Object
19 20 21 |
# File 'lib/tdc/extended_attributes/interpreter_registry.rb', line 19 def clear @interpreters = [] end |
#interpreters ⇒ Object
23 24 25 |
# File 'lib/tdc/extended_attributes/interpreter_registry.rb', line 23 def interpreters @interpreters.empty? ? [default_interpreter] : @interpreters end |
#register_interpreter(interpreter) ⇒ Object
27 28 29 30 31 32 33 34 35 36 |
# File 'lib/tdc/extended_attributes/interpreter_registry.rb', line 27 def register_interpreter(interpreter) raise Tdc::FatalError, <<~MSG.chomp unless interpreter.is_a?(Tdc::ExtendedAttributes::InterpreterBase) Cannot register an interpreter unless it inherits from Tdc::ExtendedAttributes::InterpreterBase MSG # Avoid registering the same class of interpreter a second time. return if @interpreters.map(&:class).include?(interpreter.class) @interpreters << interpreter end |