Sha256: 378ebbd11dc25adc370760f7d455722ffcb1e0d65af74d5e877b99ece1a77722

Contents?: true

Size: 805 Bytes

Versions: 7

Compression:

Stored size: 805 Bytes

Contents

require "gm/notepad/input_handlers/default_handler"
module Gm
  module Notepad
    # Responsible for registering the various input handlers
    class InputHandlerRegistry
      def initialize
        @registry = []
        yield(self) if block_given?
      end

      def handler_for(input:, skip_default: false)
        handler = nil
        @registry.each do |handler_builder|
          if handler = handler_builder.build_if_handled(input: input)
            break
          end
        end
        return handler if handler
        return nil if skip_default
        default_handler_builder.build_if_handled(input: input)
      end

      def register(handler:)
        @registry << handler
      end

      def default_handler_builder
        InputHandlers::DefaultHandler
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
gm-notepad-0.0.10 lib/gm/notepad/input_handler_registry.rb
gm-notepad-0.0.9 lib/gm/notepad/input_handler_registry.rb
gm-notepad-0.0.8 lib/gm/notepad/input_handler_registry.rb
gm-notepad-0.0.6 lib/gm/notepad/input_handler_registry.rb
gm-notepad-0.0.5 lib/gm/notepad/input_handler_registry.rb
gm-notepad-0.0.4 lib/gm/notepad/input_handler_registry.rb
gm-notepad-0.0.3 lib/gm/notepad/input_handler_registry.rb