Permalink
Browse files

Implicit method/methods option

  • Loading branch information...
1 parent f76b4ee commit 77e4c2b177976f20761122dafa4c3045058d302a @gcao committed Mar 20, 2012
Showing with 41 additions and 0 deletions.
  1. +9 −0 lib/aspector/base_class_methods.rb
  2. +32 −0 spec/unit/before_spec.rb
@@ -31,6 +31,13 @@ def aop_default_options
alias :default_options :aop_default_options
def aop_apply target, options = {}
+ # Handle 'Klass#method' shortcut
+ if target.is_a? String
+ target, method = target.split('#')
+ target = Object.const_get target
+ options.merge! :method => method
+ end
+
aspect_instance = new(target, options)
aspect_instance.send :aop_apply
aspect_instance
@@ -100,6 +107,8 @@ def aop_create_advice meta_data, klass_or_module, *methods, &block
with_method = methods.pop unless block_given?
+ methods << aop_options[:method] << aop_options[:methods] if methods.empty?
+
Aspector::Advice.new(self,
meta_data.advice_type,
Aspector::MethodMatcher.new(*methods),
View
@@ -77,5 +77,37 @@ def do_this method
obj.value.should == %w"do_this(test) test"
end
+ it "implicit method option" do
+ ImplicitMethodOptionTest = create_test_class do
+ def do_this
+ value << "do_this"
+ end
+ end
+
+ aspector "ImplicitMethodOptionTest#test" do
+ before :do_this
+ end
+
+ o = ImplicitMethodOptionTest.new
+ o.test
+ o.value.should == %w"do_this test"
+ end
+
+ it "implicit methods option" do
+ klass = create_test_class do
+ def do_this
+ value << "do_this"
+ end
+ end
+
+ aspector klass, :methods => [:test] do
+ before :do_this
+ end
+
+ o = ImplicitMethodOptionTest.new
+ o.test
+ o.value.should == %w"do_this test"
+ end
+
end

0 comments on commit 77e4c2b

Please sign in to comment.