Class: Telegram::Callback
- Inherits:
-
Object
- Object
- Telegram::Callback
- Defined in:
- lib/telegram/callback.rb
Overview
Note:
You don’t need to make this callback object without when it needed
Callback class for em-synchrony
Instance Attribute Summary collapse
-
#data ⇒ Object
readonly
Data.
Instance Method Summary collapse
-
#callback(&cb) ⇒ Object
Set a callback to be called when succeed.
-
#errback(&cb) ⇒ Object
Set a callback to be called when failed.
-
#initialize ⇒ Callback
constructor
A new instance of Callback.
-
#trigger(type = :success, data = nil) ⇒ Object
Trigger either success or error actions with data.
Constructor Details
#initialize ⇒ Callback
Returns a new instance of Callback.
11 12 13 14 15 |
# File 'lib/telegram/callback.rb', line 11 def initialize @success = nil @fail = nil @data = nil end |
Instance Attribute Details
#data ⇒ Object (readonly)
Returns Data.
9 10 11 |
# File 'lib/telegram/callback.rb', line 9 def data @data end |
Instance Method Details
#callback(&cb) ⇒ Object
Set a callback to be called when succeed
20 21 22 |
# File 'lib/telegram/callback.rb', line 20 def callback(&cb) @success = cb end |
#errback(&cb) ⇒ Object
Set a callback to be called when failed
27 28 29 |
# File 'lib/telegram/callback.rb', line 27 def errback(&cb) @fail = cb end |
#trigger(type = :success, data = nil) ⇒ Object
Trigger either success or error actions with data
35 36 37 38 39 40 41 42 43 |
# File 'lib/telegram/callback.rb', line 35 def trigger(type = :success, data = nil) @data = data case type when :success @success.call when :fail @fail.call end end |