Class: Messaging::Routing::Route
- Inherits:
-
Object
- Object
- Messaging::Routing::Route
- Defined in:
- lib/messaging/routing/route.rb
Overview
Internal: Used by routing to match a pattern against a callable (handler)
Direct Known Subclasses
Instance Attribute Summary collapse
-
#handler ⇒ Object
readonly
Returns the value of attribute handler.
-
#matcher ⇒ Object
readonly
Returns the value of attribute matcher.
Instance Method Summary collapse
- #call(message, context = self) ⇒ Object
- #categories ⇒ Object
-
#initialize(pattern, handler) ⇒ Route
constructor
A new instance of Route.
- #topics ⇒ Object
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
#handler ⇒ Object (readonly)
Returns the value of attribute handler.
10 11 12 |
# File 'lib/messaging/routing/route.rb', line 10 def handler @handler end |
#matcher ⇒ Object (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(, context = self) return unless @matcher.matches?() context.instance_exec(, &@handler) end |
#categories ⇒ Object
28 29 30 |
# File 'lib/messaging/routing/route.rb', line 28 def categories matcher.categories end |
#topics ⇒ Object
24 25 26 |
# File 'lib/messaging/routing/route.rb', line 24 def topics matcher.topics end |