Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Added HookGroup#unbind, HookGroup#within

  • Loading branch information...
commit 631298daa3420905b6b580771f0d5743dbe0f582 1 parent 999a026
Kaoru Kobo authored
Showing with 41 additions and 0 deletions.
  1. +21 −0 lib/rhook.rb
  2. +20 −0 spec/rhook_spec.rb
View
21 lib/rhook.rb
@@ -463,6 +463,27 @@ def disable
self
end
+ # Unbind the hooks.
+ # @return [self]
+ # @see Hook#unbind
+ def unbind
+ @hooks.each do |h|
+ h.unbind
+ end
+ self
+ end
+
+ # After executing block, do {#unbind}.
+ # @return nil (Should return either self or block's result...?)
+ def within(&block)
+ begin
+ yield
+ ensure
+ unbind
+ end
+ nil
+ end
+
# Tests the given hook is registered in this group.
# @return [Boolean]
def include?(hook)
View
20 spec/rhook_spec.rb
@@ -216,6 +216,26 @@ def group_2
t.group_2.should == "g2"
end
+ example "within by group" do
+ group = RHook.group do
+ Target._rhook.hack(:group_1) do |inv|
+ "hack1"
+ end
+ Target._rhook.hack(:group_2) do |inv|
+ "hack2"
+ end
+ end
+
+ t = Target.new
+ group.within do
+ t.group_1.should == "hack1"
+ t.group_2.should == "hack2"
+ end
+ t.group_1.should == "g1"
+ t.group_2.should == "g2"
+ end
+
+
example "Nested group" do
@parent_group = RHook.group do
Target._rhook.hack(:group_1) do |inv|
Please sign in to comment.
Something went wrong with that request. Please try again.