Sha256: 3af02436a65c0272c8a034ddbce4383e0f7239a249e8e3113d56356ee63fa2fe
Contents?: true
Size: 1.19 KB
Versions: 14
Compression:
Stored size: 1.19 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 def categories all_matching_messages.map { |m| m.new.stream_category }.uniq end end end end
Version data entries
14 entries across 14 versions & 1 rubygems