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.respond_to?(:to_proc) ? handler : handler.method(:call)
  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, context = self) ⇒ Object



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

def call(message, context = self)
  return unless @matcher.matches?(message)

  context.instance_exec(message, &@handler)
end

#topicsObject



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

def topics
  matcher.topics
end