Class: Telegram::Callback

Inherits:
Object
  • Object
show all
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

See Also:

Version:

  • 0.1.0

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeCallback

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

#dataObject (readonly)

Returns Data.

Returns:

  • (Object)

    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

Parameters:

  • cb (Block)


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

Parameters:

  • cb (Block)


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

Parameters:

  • type (Symbol) (defaults to: :success)

    :success or :fail

  • data (Object) (defaults to: nil)


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