Class: PubControlCallbackHandler

Inherits:
Object
  • Object
show all
Defined in:
lib/pccbhandler.rb

Overview

format.rb

~~~~~~~~~
This module implements the PubControlCallbackHandler class.
:authors: Konstantin Bokarius.
:copyright: (c) 2015 by Fanout, Inc.
:license: MIT, see LICENSE for more details.

Instance Method Summary collapse

Constructor Details

#initialize(num_calls, callback) ⇒ PubControlCallbackHandler

Returns a new instance of PubControlCallbackHandler.



9
10
11
12
13
14
# File 'lib/pccbhandler.rb', line 9

def initialize(num_calls, callback)
  @num_calls = num_calls
  @callback = callback
  @success = true
  @first_error_message = nil
end

Instance Method Details

#handler(success, message) ⇒ Object



16
17
18
19
20
21
22
23
24
25
# File 'lib/pccbhandler.rb', line 16

def handler(success, message)
  if !success and @success
    @success = false
    @first_error_message = message
  end
  @num_calls -= 1
  if @num_calls <= 0
    @callback.call(@success, @first_error_message)
  end
end

#handler_method_symbolObject

TODO: how to get handler symbol without this method?



28
29
30
# File 'lib/pccbhandler.rb', line 28

def handler_method_symbol
  return method(:handler)
end