Sha256: c13a0eab71e533b306c2dff182159bb0bc556d2fc263f53223e2ce3c2195ea0b
Contents?: true
Size: 605 Bytes
Versions: 2
Compression:
Stored size: 605 Bytes
Contents
# frozen_string_literal: true module Del # This class is the default router used # to route chat messages to chat routes. class DefaultRouter def initialize(routes = []) @routes = routes end def register(pattern, &block) @routes.push(pattern: pattern, command: block) end def route(message) @routes.each do |route| next unless (matches = route[:pattern].match(message.text)) begin route[:command].call(message, matches) rescue StandardError => error Del.logger.error(error) end end end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
del-0.1.18 | lib/del/default_router.rb |
del-0.1.17 | lib/del/default_router.rb |