Class: Del::DefaultRouter
- Inherits:
-
Object
- Object
- Del::DefaultRouter
- Defined in:
- lib/del/default_router.rb
Overview
This class is the default router used to route chat messages to chat routes.
Instance Method Summary collapse
-
#initialize(routes = []) ⇒ DefaultRouter
constructor
A new instance of DefaultRouter.
- #register(pattern, &block) ⇒ Object
- #route(message) ⇒ Object
Constructor Details
#initialize(routes = []) ⇒ DefaultRouter
Returns a new instance of DefaultRouter.
7 8 9 |
# File 'lib/del/default_router.rb', line 7 def initialize(routes = []) @routes = routes end |
Instance Method Details
#register(pattern, &block) ⇒ Object
11 12 13 |
# File 'lib/del/default_router.rb', line 11 def register(pattern, &block) @routes.push(pattern: pattern, command: block) end |
#route(message) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/del/default_router.rb', line 15 def route() @routes.each do |route| next unless (matches = route[:pattern].match(.text)) begin route[:command].call(, matches) rescue StandardError => error Del.logger.error(error) end end end |