Class: Fizzy::ChainHooks

Inherits:
Object
  • Object
show all
Includes:
Hooks
Defined in:
lib/fizzy/chain_hooks.rb

Overview

Composes multiple Hooks implementations, calling them in sequence. Start events are called in order; end events are called in reverse order.

Instance Method Summary collapse

Constructor Details

#initialize(*hooks) ⇒ ChainHooks

Returns a new instance of ChainHooks.



9
10
11
# File 'lib/fizzy/chain_hooks.rb', line 9

def initialize(*hooks)
  @hooks = hooks
end

Instance Method Details

#on_operation_end(info, result) ⇒ Object



17
18
19
# File 'lib/fizzy/chain_hooks.rb', line 17

def on_operation_end(info, result)
  @hooks.reverse_each { |h| safe_call { h.on_operation_end(info, result) } }
end

#on_operation_start(info) ⇒ Object



13
14
15
# File 'lib/fizzy/chain_hooks.rb', line 13

def on_operation_start(info)
  @hooks.each { |h| safe_call { h.on_operation_start(info) } }
end

#on_paginate(url, page) ⇒ Object



33
34
35
# File 'lib/fizzy/chain_hooks.rb', line 33

def on_paginate(url, page)
  @hooks.each { |h| safe_call { h.on_paginate(url, page) } }
end

#on_request_end(info, result) ⇒ Object



25
26
27
# File 'lib/fizzy/chain_hooks.rb', line 25

def on_request_end(info, result)
  @hooks.reverse_each { |h| safe_call { h.on_request_end(info, result) } }
end

#on_request_start(info) ⇒ Object



21
22
23
# File 'lib/fizzy/chain_hooks.rb', line 21

def on_request_start(info)
  @hooks.each { |h| safe_call { h.on_request_start(info) } }
end

#on_retry(info, attempt, error, delay) ⇒ Object



29
30
31
# File 'lib/fizzy/chain_hooks.rb', line 29

def on_retry(info, attempt, error, delay)
  @hooks.each { |h| safe_call { h.on_retry(info, attempt, error, delay) } }
end