Sha256: ae5acd068e35cccef20694aa8c4c87c5418978679882bd632d0762793fdeb4fb
Contents?: true
Size: 833 Bytes
Versions: 15
Compression:
Stored size: 833 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 private def verify_handler! raise ArgumentError, 'Handler must be callable' unless handler.respond_to? :call end end end end
Version data entries
15 entries across 15 versions & 1 rubygems