Class: Messaging::Routing::Route

Inherits:
Object
  • Object
show all
Defined in:
lib/messaging/routing/route.rb

Overview

Internal: Used by routing to match a pattern against a callable (handler)

Direct Known Subclasses

EnqueuedRoute

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(pattern, handler) ⇒ Route

Returns a new instance of Route.



12
13
14
15
16
# File 'lib/messaging/routing/route.rb', line 12

def initialize(pattern, handler)
  @matcher = MessageMatcher.new(pattern: pattern)
  @handler = handler
  verify_handler!
end

Instance Attribute Details

#handlerObject (readonly)

Returns the value of attribute handler.



10
11
12
# File 'lib/messaging/routing/route.rb', line 10

def handler
  @handler
end

#matcherObject (readonly)

Returns the value of attribute matcher.



9
10
11
# File 'lib/messaging/routing/route.rb', line 9

def matcher
  @matcher
end

Instance Method Details

#call(message) ⇒ Object



18
19
20
21
22
# File 'lib/messaging/routing/route.rb', line 18

def call(message)
  return unless @matcher.matches?(message)

  @handler.call(message)
end

#topicsObject



24
25
26
# File 'lib/messaging/routing/route.rb', line 24

def topics
  matcher.topics
end