Permalink
Browse files

added specs and behavior for creating hooks on proxied objects, not j…

…ust classes
  • Loading branch information...
1 parent 7797650 commit 43d02ef42916e5476da019f536357a49a9d5a454 @jacaetevha committed Feb 12, 2011
Showing with 31 additions and 0 deletions.
  1. +16 −0 lib/proxeze/instance_methods.rb
  2. +15 −0 spec/proxeze_spec.rb
@@ -9,6 +9,22 @@ def clone
def new_proxy
Proxeze.for __getobj__
end
+
+ def after mid, &blk
+ self.class.after mid, &blk
+ end
+
+ def after_all &blk
+ self.class.after_all &blk
+ end
+
+ def before mid, &blk
+ self.class.before mid, &blk
+ end
+
+ def before_all &blk
+ self.class.before_all &blk
+ end
private
def execute_call container, *args
View
@@ -237,4 +237,19 @@
callbacks[:bar].should == 2.0
callbacks[:baz].should == 4.0
end
+
+ it "should be able to add hooks to a proxied instance" do
+ a = Proxeze.for [1, 3, 2, 5, 4, 6]
+ a.before :reverse do |*args|
+ target, mid, arguments = *args
+ target << target.length
+ end
+ a.reverse.should == [6, 6, 4, 5, 2, 3, 1]
+
+ a.after :sort do |*args|
+ target, result, arguments = *args
+ result.uniq
+ end
+ a.sort.should == [1, 2, 3, 4, 5, 6]
+ end
end

0 comments on commit 43d02ef

Please sign in to comment.