Sha256: fc29366ed5e0b38dd612a3c59139fade462e0a3382bb71b1ea33c0f5a52a1738
Contents?: true
Size: 892 Bytes
Versions: 14
Compression:
Stored size: 892 Bytes
Contents
require 'dry-equalizer' module Messaging module Routing # Internal: Used by routing to match a pattern against a callable (handler) class Route include Dry::Equalizer(:matcher, :handler) attr_reader :matcher attr_reader :handler def initialize(pattern, handler) @matcher = MessageMatcher.new(pattern: pattern) @handler = handler.respond_to?(:to_proc) ? handler : handler.method(:call) verify_handler! end def call(message, context = self) return unless @matcher.matches?(message) context.instance_exec(message, &@handler) end def topics matcher.topics end def categories matcher.categories end private def verify_handler! raise ArgumentError, 'Handler must be callable' unless handler.respond_to? :call end end end end
Version data entries
14 entries across 14 versions & 1 rubygems