Class: Peeek::Hooks
- Inherits:
-
Array
- Object
- Array
- Peeek::Hooks
- Defined in:
- lib/peeek/hooks.rb
Instance Method Summary collapse
-
#circumvent { ... } ⇒ Object
Run process while circumvent the hooks.
-
#clear ⇒ Object
Clear the hooks.
-
#get(object, method_name = nil) ⇒ Peeek::Hook?
Get a hook by an object and a method name.
Instance Method Details
#circumvent { ... } ⇒ Object
Run process while circumvent the hooks.
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 |
#clear ⇒ Object
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 |