Sha256: fe134fe361a75ba40e44b10097afd385ff96b451b21d0d3bf6616dc3dac667f6
Contents?: true
Size: 1.09 KB
Versions: 19
Compression:
Stored size: 1.09 KB
Contents
require 'dry-equalizer' module Messaging module Routing # Internal: Used by subscribers to match messages. class MessageMatcher include Dry::Equalizer(:pattern) attr_accessor :pattern def initialize(pattern:) self.pattern = pattern end # Internal: See routing.rb for examples on how it is used. def matches?(message) matches_pattern?(message) end def matches_pattern?(message) case pattern when Regexp pattern =~ message.message_type when Class, Module /^#{pattern}/ =~ message.message_type when Proc pattern.call(message) else false end end def call(message) matches?(message) end def all_matching_messages Messaging.defined_messages.select(&method(:matches?)) end # Internal: Get all topics that the matcher would need to match a message. # # Used by the Kafka adapter to setup consumers. def topics all_matching_messages.map(&:topic).uniq end end end end
Version data entries
19 entries across 19 versions & 1 rubygems