Module: Ethon::Easy::ResponseCallbacks

Included in:
Ethon::Easy
Defined in:
lib/ethon/easy/response_callbacks.rb

Overview

This module contains the logic for the response callbacks. The on_complete callback is the only one at the moment.

You can set multiple callbacks, which are then executed in the same order.

easy.on_complete { p 1 }
easy.on_complete { p 2 }
easy.complete
#=> 1
#=> 2

You can clear the callbacks:

easy.on_complete { p 1 }
easy.on_complete { p 2 }
easy.on_complete.clear
easy.on_complete
#=> []

Instance Method Summary collapse

Instance Method Details

#completeObject

Execute on_complete callbacks.

Examples:

Execute on_completes.

request.complete


43
44
45
46
47
# File 'lib/ethon/easy/response_callbacks.rb', line 43

def complete
  if defined?(@on_complete)
    @on_complete.map{ |callback| callback.call(self) }
  end
end

#on_complete(&block) ⇒ Object

Set on_complete callback.

Examples:

Set on_complete.

request.on_complete { p "yay" }

Parameters:

  • block (Block)

    The block to execute.



33
34
35
36
37
# File 'lib/ethon/easy/response_callbacks.rb', line 33

def on_complete(&block)
  @on_complete ||= []
  @on_complete << block if block_given?
  @on_complete
end