Module: TelegramBot::EventHandler

Included in:
TelegramBot
Defined in:
lib/telegram_bot/handler.rb

Defined Under Namespace

Modules: PrependMethods Classes: Handler

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(clazz) ⇒ Object



40
41
42
# File 'lib/telegram_bot/handler.rb', line 40

def self.included(clazz)
  clazz.prepend PrependMethods
end

Instance Method Details

#handle(msg) ⇒ Object



53
54
55
56
57
58
59
60
61
62
63
# File 'lib/telegram_bot/handler.rb', line 53

def handle(msg)
  @handlers.each do |hndlr|
    next unless hndlr === msg

    proxy = MessageProxy.new(self, msg, hndlr)
    proxy.instance_exec(*hndlr.arguments(msg),
                        &hndlr.action)

    break unless hndlr.pass?
  end
end

#on(type, *args, pass: false, &block) ⇒ Object



45
46
47
48
49
50
51
# File 'lib/telegram_bot/handler.rb', line 45

def on(type, *args, pass: false, &block)
  matcher_class_name = "telegram_bot/#{type}_matcher".classify
  matcher_class = matcher_class_name.constantize
  matcher = matcher_class.new(*args)
  handler = Handler.new(matcher, block, pass)
  @handlers << handler
end