Class: PubControlCallbackHandler

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

Overview

format.rb

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

Instance Method Summary collapse

Constructor Details

#initialize(num_calls, callback) ⇒ PubControlCallbackHandler

Returns a new instance of PubControlCallbackHandler.



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

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



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

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?



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

def handler_method_symbol
  return method(:handler)
end