Class: Peeek::Hooks

Inherits:
Array
  • Object
show all
Defined in:
lib/peeek/hooks.rb

Instance Method Summary collapse

Instance Method Details

#circumvent { ... } ⇒ Object

Run process while circumvent the hooks.

Yields:

  • any process that wants to run while circumvent the hooks

Raises:

  • (ArgumentError)


33
34
35
36
37
38
39
40
41
42
43
# File 'lib/peeek/hooks.rb', line 33

def circumvent
  raise ArgumentError, 'block not supplied' unless block_given?

  linked_hooks = select(&:linked?).each(&:unlink)

  begin
    yield
  ensure
    linked_hooks.each(&:link)
  end
end

#clearObject

Clear the hooks.



21
22
23
24
25
26
27
28
# File 'lib/peeek/hooks.rb', line 21

def clear
  each do |hook|
    hook.unlink
    hook.calls.clear
  end

  super
end

#get(object, method_name = nil) ⇒ Peeek::Hook?

Get a hook by an object and a method name.



12
13
14
15
16
17
18
# File 'lib/peeek/hooks.rb', line 12

def get(object, method_name = nil)
  if method_name.nil?
    find { |hook| hook.object == object }
  else
    find { |hook| hook.object == object && hook.method_name == method_name }
  end
end