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.
13 14 15 |
# File 'lib/tdc/extended_attributes/interpreter_registry.rb', line 13 def initialize @interpreters = [] end |
Class Method Details
.register(interpreter:) ⇒ Object
9 10 11 |
# File 'lib/tdc/extended_attributes/interpreter_registry.rb', line 9 def self.register(interpreter:) instance.register_interpreter(interpreter) end |
Instance Method Details
#clear ⇒ Object
17 18 19 |
# File 'lib/tdc/extended_attributes/interpreter_registry.rb', line 17 def clear @interpreters = [] end |
#interpreters ⇒ Object
21 22 23 |
# File 'lib/tdc/extended_attributes/interpreter_registry.rb', line 21 def interpreters @interpreters.empty? ? [default_interpreter] : @interpreters end |
#register_interpreter(interpreter) ⇒ Object
25 26 27 28 29 30 31 32 33 34 |
# File 'lib/tdc/extended_attributes/interpreter_registry.rb', line 25 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 |