Sha256: 0ab9fd560fea03f121becc224c43219dc1e428d2a44b0ab2b9101646f45c50c9

Contents?: true

Size: 919 Bytes

Versions: 5

Compression:

Stored size: 919 Bytes

Contents

module Tdc
  module ExtendedAttributes
    #
    # Knows the class instances that interpret extended attribute values.
    #
    class InterpreterRegistry
      include Singleton

      def self.register(interpreter:)
        instance.register_interpreter(interpreter)
      end

      def initialize
        @interpreters = []
      end

      def interpreters
        @interpreters.empty? ? [default_interpreter] : @interpreters
      end

      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

        @interpreters << interpreter
      end

      private

      def default_interpreter
        @_default_interpreter ||= Tdc::ExtendedAttributes::DefaultInterpreter.new
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
tdc-0.4.4 lib/tdc/extended_attributes/interpreter_registry.rb
tdc-0.4.3.1 lib/tdc/extended_attributes/interpreter_registry.rb
tdc-0.4.3 lib/tdc/extended_attributes/interpreter_registry.rb
tdc-0.4.2 lib/tdc/extended_attributes/interpreter_registry.rb
tdc-0.4.1 lib/tdc/extended_attributes/interpreter_registry.rb