Class: Diligence::Router
- Inherits:
-
Object
- Object
- Diligence::Router
- Defined in:
- lib/diligence/router.rb
Instance Attribute Summary collapse
-
#routes ⇒ Object
readonly
Returns the value of attribute routes.
Instance Method Summary collapse
- #channel(to:) ⇒ Object
- #chat(chat_id, to:) ⇒ Object
- #default(to:) ⇒ Object
- #dialog(to:) ⇒ Object
- #draw(&block) ⇒ Object
- #group(to:) ⇒ Object
-
#initialize ⇒ Router
constructor
A new instance of Router.
- #match(message_update) ⇒ Object
- #message_type(type, to:) ⇒ Object
- #text_matches(pattern, to:) ⇒ Object
- #user(user_id, to:) ⇒ Object
Constructor Details
#initialize ⇒ Router
Returns a new instance of Router.
7 8 9 |
# File 'lib/diligence/router.rb', line 7 def initialize @routes = [] end |
Instance Attribute Details
#routes ⇒ Object (readonly)
Returns the value of attribute routes.
5 6 7 |
# File 'lib/diligence/router.rb', line 5 def routes @routes end |
Instance Method Details
#channel(to:) ⇒ Object
32 33 34 |
# File 'lib/diligence/router.rb', line 32 def channel(to:) add_route(type: :chat_type, matcher: 'channel', handler: to) end |
#chat(chat_id, to:) ⇒ Object
16 17 18 |
# File 'lib/diligence/router.rb', line 16 def chat(chat_id, to:) add_route(type: :chat_id, matcher: chat_id, handler: to) end |
#default(to:) ⇒ Object
44 45 46 |
# File 'lib/diligence/router.rb', line 44 def default(to:) add_route(type: :default, matcher: nil, handler: to) end |
#dialog(to:) ⇒ Object
24 25 26 |
# File 'lib/diligence/router.rb', line 24 def dialog(to:) add_route(type: :chat_type, matcher: 'private', handler: to) end |
#draw(&block) ⇒ Object
11 12 13 14 |
# File 'lib/diligence/router.rb', line 11 def draw(&block) instance_eval(&block) self end |
#group(to:) ⇒ Object
28 29 30 |
# File 'lib/diligence/router.rb', line 28 def group(to:) add_route(type: :chat_type, matcher: %w[group supergroup], handler: to) end |
#match(message_update) ⇒ Object
48 49 50 51 52 53 54 |
# File 'lib/diligence/router.rb', line 48 def match() @routes.each do |route| handler = route.match() return handler if handler end nil end |
#message_type(type, to:) ⇒ Object
36 37 38 |
# File 'lib/diligence/router.rb', line 36 def (type, to:) add_route(type: :message_type, matcher: type, handler: to) end |
#text_matches(pattern, to:) ⇒ Object
40 41 42 |
# File 'lib/diligence/router.rb', line 40 def text_matches(pattern, to:) add_route(type: :text_pattern, matcher: pattern, handler: to) end |
#user(user_id, to:) ⇒ Object
20 21 22 |
# File 'lib/diligence/router.rb', line 20 def user(user_id, to:) add_route(type: :user_id, matcher: user_id, handler: to) end |