Module: Cramp::Callbacks

Extended by:
ActiveSupport::Concern
Included in:
Abstract
Defined in:
lib/cramp/callbacks.rb

Defined Under Namespace

Modules: ClassMethods

Instance Method Summary collapse

Instance Method Details

#before_start(n = 0) ⇒ Object



34
35
36
37
38
39
40
# File 'lib/cramp/callbacks.rb', line 34

def before_start(n = 0)
  if callback = self.class.before_start_callbacks[n]
    callback_wrapper { send(callback) { before_start(n+1) } }
  else
    continue
  end
end

#callback_wrapperObject



56
57
58
59
60
61
62
63
64
# File 'lib/cramp/callbacks.rb', line 56

def callback_wrapper
  EM.next_tick do
    begin
      yield
    rescue StandardError, LoadError, SyntaxError => exception
      handle_exception(exception)
    end
  end
end

#on_finishObject



50
51
52
53
54
# File 'lib/cramp/callbacks.rb', line 50

def on_finish
  self.class.on_finish_callbacks.each do |callback|
    callback_wrapper { send(callback) }
  end
end

#on_startObject



42
43
44
45
46
47
48
# File 'lib/cramp/callbacks.rb', line 42

def on_start
  callback_wrapper { start } if respond_to?(:start)

  self.class.on_start_callback.each do |callback|
    callback_wrapper { send(callback) unless @finished }
  end
end