Skip to content

Commit

Permalink
Minor adjustments
Browse files Browse the repository at this point in the history
New spec for inheriting advice
  • Loading branch information
gcao committed May 1, 2011
1 parent cad0206 commit 74de627
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 5 deletions.
4 changes: 1 addition & 3 deletions README.rdoc
Expand Up @@ -59,8 +59,6 @@ Execution model: http://gcao.posterous.com/aspect4r-documentation-advice-executi

See github issues http://github.com/gcao/aspect4r/issues

Use "yield *args" to call wrapped method in around advice.

Support regular expression on methods to be advised. When such an advice is defined, methods defined before it
will not be processed, only new methods are.

Expand All @@ -78,7 +76,7 @@ have same name.
Inherit advices: add option :inherit to all advices. Advices whose :inherit options are set to true will be copied to
child modules/classes. By default :inherit is set to false.

a4r_disable_advices: will remove advices with given names. If no name is given, all advices are removed.
a4r_remove_advices: will remove advices with given names. If no name is given, all advices are removed.

== Note on Patches/Pull Requests

Expand Down
27 changes: 25 additions & 2 deletions lib/aspect4r/model/method_matcher.rb
@@ -1,10 +1,33 @@
module Aspect4r
module Model
# Performance improvement ideas:
# if there is only one item in match_data, generate simplified match? method on the fly
class MethodMatcher
def initialize *match_data
@match_data = match_data

# Performance improvement ideas:
# if there is only one item in match_data, generate simplified match? method on the fly
# Seems this does not help much
#
# if match_data.size == 1
# first_item = match_data.first
# eigen_class = class << self; self; end
#
# if first_item.is_a? String
# eigen_class.send :define_method, :match? do |method|
# method == first_item
# end
# elsif first_item.is_a? Regexp
# eigen_class.send :define_method, :match? do |method|
# method =~ first_item
# end
# else
# eigen_class.send :define_method, :match? do |method|
# false
# end
# end
# else
# @match_data = match_data
# end
end

def match? method
Expand Down
34 changes: 34 additions & 0 deletions spec/aspect4r/class_inheritance_spec.rb
Expand Up @@ -251,4 +251,38 @@ class Child2 < parent

o.value.should == %w(around(before) before test after around(after))
end

it "inherit advice from module" do
pending
mod = Module.new do
include Aspect4r

before :test, :inherit => true do
@value << "before"
end

after :test do
@value << "after"
end
end

klass = Class.new do
include mod

attr :value

def initialize
@value = []
end

def test
@value << "test"
end
end

o = klass.new
o.test

o.value.should == %w(before test)
end
end

0 comments on commit 74de627

Please sign in to comment.