Class: Messaging::Routing::MessageMatcher
- Inherits:
-
Object
- Object
- Messaging::Routing::MessageMatcher
- Defined in:
- lib/messaging/routing/message_matcher.rb
Overview
Internal: Used by subscribers to match messages.
Instance Attribute Summary collapse
-
#pattern ⇒ Object
Returns the value of attribute pattern.
Instance Method Summary collapse
- #all_matching_messages ⇒ Object
- #call(message) ⇒ Object
- #categories ⇒ Object
-
#initialize(pattern:) ⇒ MessageMatcher
constructor
A new instance of MessageMatcher.
-
#matches?(message) ⇒ Boolean
Internal: See routing.rb for examples on how it is used.
- #matches_pattern?(message) ⇒ Boolean
-
#topics ⇒ Object
Internal: Get all topics that the matcher would need to match a message.
Constructor Details
#initialize(pattern:) ⇒ MessageMatcher
Returns a new instance of MessageMatcher.
10 11 12 |
# File 'lib/messaging/routing/message_matcher.rb', line 10 def initialize(pattern:) self.pattern = pattern end |
Instance Attribute Details
#pattern ⇒ Object
Returns the value of attribute pattern.
8 9 10 |
# File 'lib/messaging/routing/message_matcher.rb', line 8 def pattern @pattern end |
Instance Method Details
#all_matching_messages ⇒ Object
36 37 38 |
# File 'lib/messaging/routing/message_matcher.rb', line 36 def Messaging..select(&method(:matches?)) end |
#call(message) ⇒ Object
32 33 34 |
# File 'lib/messaging/routing/message_matcher.rb', line 32 def call() matches?() end |
#categories ⇒ Object
47 48 49 |
# File 'lib/messaging/routing/message_matcher.rb', line 47 def categories .map { |m| m.new.stream_category }.uniq end |
#matches?(message) ⇒ Boolean
Internal: See routing.rb for examples on how it is used.
15 16 17 |
# File 'lib/messaging/routing/message_matcher.rb', line 15 def matches?() matches_pattern?() end |
#matches_pattern?(message) ⇒ Boolean
19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/messaging/routing/message_matcher.rb', line 19 def matches_pattern?() case pattern when Regexp pattern =~ . when Class, Module /^#{pattern}/ =~ . when Proc pattern.call() else false end end |
#topics ⇒ Object
Internal: Get all topics that the matcher would need to match a message.
Used by the Kafka adapter to setup consumers.
43 44 45 |
# File 'lib/messaging/routing/message_matcher.rb', line 43 def topics .map(&:topic).uniq end |