aspect4r 0.9.0 → 0.9.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (34) hide show
  1. data/README.rdoc +23 -4
  2. data/VERSION +1 -1
  3. data/aspect4r.gemspec +11 -9
  4. data/examples/advices_on_class_method_example.rb +2 -2
  5. data/examples/around_example.rb +2 -2
  6. data/examples/combined_example.rb +2 -2
  7. data/examples/test_advices_example.rb +3 -4
  8. data/lib/aspect4r/base.rb +25 -23
  9. data/lib/aspect4r/helper.rb +34 -17
  10. data/lib/aspect4r/model/advice.rb +29 -4
  11. data/lib/aspect4r/model/aspect_data.rb +14 -5
  12. data/lib/aspect4r/model/method_matcher.rb +43 -0
  13. data/spec/aspect4r/advice_on_class_method_spec.rb +4 -4
  14. data/spec/aspect4r/advice_test_spec.rb +9 -20
  15. data/spec/aspect4r/around_spec.rb +23 -24
  16. data/spec/aspect4r/before_spec.rb +1 -1
  17. data/spec/aspect4r/class_inheritance_spec.rb +40 -6
  18. data/spec/aspect4r/classic_spec.rb +2 -2
  19. data/spec/aspect4r/helper_spec.rb +2 -2
  20. data/spec/aspect4r/inheritance_inclusion_combined_spec.rb +4 -4
  21. data/spec/aspect4r/method_added_spec.rb +2 -2
  22. data/spec/aspect4r/{advice_group_spec.rb → model/advice_group_spec.rb} +1 -1
  23. data/spec/aspect4r/model/advice_spec.rb +52 -0
  24. data/spec/aspect4r/model/method_matcher_spec.rb +23 -0
  25. data/spec/aspect4r/module_inclusion_spec.rb +8 -8
  26. data/spec/aspect4r/regexp_methods_spec.rb +47 -0
  27. data/spec/aspect4r/singleton_method_added_spec.rb +2 -2
  28. data/spec/aspect4r_spec.rb +58 -22
  29. data/test/around_test.rb +2 -2
  30. data/test/combined_test.rb +2 -2
  31. metadata +13 -11
  32. data/lib/aspect4r/model/advices_for_method.rb +0 -26
  33. data/spec/aspect4r/advice_spec.rb +0 -62
  34. data/spec/aspect4r/advices_for_method_spec.rb +0 -17
data/README.rdoc CHANGED
@@ -24,7 +24,7 @@ API documentation: http://gcao.posterous.com/aspect4r-usage-and-public-api
24
24
  puts "entering test(#{value})"
25
25
  end
26
26
 
27
- before :test, :do_something
27
+ before :test, :do_something
28
28
 
29
29
  before_filter :test do |value|
30
30
  value >= 0
@@ -59,11 +59,30 @@ Execution model: http://gcao.posterous.com/aspect4r-documentation-advice-executi
59
59
 
60
60
  See github issues http://github.com/gcao/aspect4r/issues
61
61
 
62
- Experiment: change Base.included to define method_added and singleton_method_added. This will restrict
63
- impact on the class that includes Aspect4r
62
+ Support regular expression on methods to be advised. When such an advice is defined, methods defined before it
63
+ will not be processed, only new methods are.
64
+
65
+ Advices are stored in an array. Whenever a method is created, the whole array is checked to find the advices that
66
+ are applicable to it. Those applicable advices are used to construct the new method. This provides a lot
67
+ flexibilities but can be a performance burden.
68
+
69
+ One way to improve performance is to use array to store advices that use regular expression. Advices specific to
70
+ methods are stored in hash. (Do this only when performance is proved to be a problem in real world scenarios)
71
+
72
+ Advice name: each advice can take a :name option. If no name is given, the advice method name is used as the advice
73
+ name. If advice logic is in a block and :name is not set, the advice will not have a name. Multiple advices can
74
+ have same name.
75
+ What use can this bring? skip advice for specific methods. debugging purpose. testing purpose.
76
+
77
+ Inherit advices: add option :inherit to all advices. Advices whose :inherit options are set to true will be copied to
78
+ child modules/classes. By default :inherit is set to false.
79
+ This adds a lot complexity and might not be a good idea.
80
+ This can be achieved by putting advices in ModuleX.included or ClassY.inherited
81
+
82
+ a4r_remove_advices: will remove advices with given names. If no name is given, all advices are removed.
64
83
 
65
84
  == Note on Patches/Pull Requests
66
-
85
+
67
86
  * Fork the project.
68
87
  * Make your feature addition or bug fix.
69
88
  * Add tests for it. This is important so I don't break it in a
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.9.0
1
+ 0.9.1
data/aspect4r.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{aspect4r}
8
- s.version = "0.9.0"
8
+ s.version = "0.9.1"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Guoliang Cao"]
12
- s.date = %q{2011-04-29}
12
+ s.date = %q{2011-05-02}
13
13
  s.description = %q{AOP for ruby - use before, after and around to trim your fat methods and reduce code duplication}
14
14
  s.email = %q{gcao99@gmail.com}
15
15
  s.extra_rdoc_files = [
@@ -39,15 +39,12 @@ Gem::Specification.new do |s|
39
39
  "lib/aspect4r/helper.rb",
40
40
  "lib/aspect4r/model/advice.rb",
41
41
  "lib/aspect4r/model/advice_metadata.rb",
42
- "lib/aspect4r/model/advices_for_method.rb",
43
42
  "lib/aspect4r/model/aspect_data.rb",
43
+ "lib/aspect4r/model/method_matcher.rb",
44
44
  "lib/aspect4r/return_this.rb",
45
- "spec/aspect4r/advice_group_spec.rb",
46
45
  "spec/aspect4r/advice_on_class_method_spec.rb",
47
46
  "spec/aspect4r/advice_scope_spec.rb",
48
- "spec/aspect4r/advice_spec.rb",
49
47
  "spec/aspect4r/advice_test_spec.rb",
50
- "spec/aspect4r/advices_for_method_spec.rb",
51
48
  "spec/aspect4r/after_spec.rb",
52
49
  "spec/aspect4r/around_spec.rb",
53
50
  "spec/aspect4r/before_spec.rb",
@@ -57,7 +54,11 @@ Gem::Specification.new do |s|
57
54
  "spec/aspect4r/include_advices_from_module_spec.rb",
58
55
  "spec/aspect4r/inheritance_inclusion_combined_spec.rb",
59
56
  "spec/aspect4r/method_added_spec.rb",
57
+ "spec/aspect4r/model/advice_group_spec.rb",
58
+ "spec/aspect4r/model/advice_spec.rb",
59
+ "spec/aspect4r/model/method_matcher_spec.rb",
60
60
  "spec/aspect4r/module_inclusion_spec.rb",
61
+ "spec/aspect4r/regexp_methods_spec.rb",
61
62
  "spec/aspect4r/singleton_method_added_spec.rb",
62
63
  "spec/aspect4r/super_in_method_spec.rb",
63
64
  "spec/aspect4r_spec.rb",
@@ -81,12 +82,9 @@ Gem::Specification.new do |s|
81
82
  "examples/before_example.rb",
82
83
  "examples/combined_example.rb",
83
84
  "examples/test_advices_example.rb",
84
- "spec/aspect4r/advice_group_spec.rb",
85
85
  "spec/aspect4r/advice_on_class_method_spec.rb",
86
86
  "spec/aspect4r/advice_scope_spec.rb",
87
- "spec/aspect4r/advice_spec.rb",
88
87
  "spec/aspect4r/advice_test_spec.rb",
89
- "spec/aspect4r/advices_for_method_spec.rb",
90
88
  "spec/aspect4r/after_spec.rb",
91
89
  "spec/aspect4r/around_spec.rb",
92
90
  "spec/aspect4r/before_spec.rb",
@@ -96,7 +94,11 @@ Gem::Specification.new do |s|
96
94
  "spec/aspect4r/include_advices_from_module_spec.rb",
97
95
  "spec/aspect4r/inheritance_inclusion_combined_spec.rb",
98
96
  "spec/aspect4r/method_added_spec.rb",
97
+ "spec/aspect4r/model/advice_group_spec.rb",
98
+ "spec/aspect4r/model/advice_spec.rb",
99
+ "spec/aspect4r/model/method_matcher_spec.rb",
99
100
  "spec/aspect4r/module_inclusion_spec.rb",
101
+ "spec/aspect4r/regexp_methods_spec.rb",
100
102
  "spec/aspect4r/singleton_method_added_spec.rb",
101
103
  "spec/aspect4r/super_in_method_spec.rb",
102
104
  "spec/aspect4r_spec.rb",
@@ -6,9 +6,9 @@ class A
6
6
  class << self
7
7
  include Aspect4r
8
8
 
9
- around :test do |proxy, input|
9
+ around :test do |input, &block|
10
10
  puts 'around test (before)'
11
- result = a4r_invoke proxy, input
11
+ result = block.call input
12
12
  puts 'around test (after)'
13
13
  result
14
14
  end
@@ -10,9 +10,9 @@ class A
10
10
  value
11
11
  end
12
12
 
13
- around :test do |proxy, value|
13
+ around :test do |value, &block|
14
14
  puts 'before test'
15
- result = a4r_invoke proxy, value
15
+ result = block.call value
16
16
  puts 'after test'
17
17
  result
18
18
  end
@@ -10,9 +10,9 @@ class A
10
10
  value
11
11
  end
12
12
 
13
- around :test do |proxy, value|
13
+ around :test do |value, &block|
14
14
  puts 'around test 1'
15
- result = a4r_invoke proxy, value
15
+ result = block.call value
16
16
  puts 'around test 2'
17
17
  result
18
18
  end
@@ -20,9 +20,9 @@ class Klass
20
20
  @value = []
21
21
  end
22
22
 
23
- around :test do |proxy, input|
23
+ around :test do |input, &block|
24
24
  @value << "around(before)"
25
- a4r_invoke proxy, input
25
+ block.call input
26
26
  @value << "around(after)"
27
27
  end
28
28
 
@@ -56,8 +56,7 @@ describe Klass do
56
56
  advice.around?.should be_true
57
57
 
58
58
  o = Klass.new
59
- o.expects(:a4r_invoke).with(:proxy, 1)
60
-
59
+
61
60
  advice.invoke(o, :proxy, 1)
62
61
 
63
62
  o.value.should == %w(around(before) around(after))
data/lib/aspect4r/base.rb CHANGED
@@ -1,8 +1,8 @@
1
1
  require 'aspect4r/errors'
2
2
  require 'aspect4r/model/advice'
3
- require 'aspect4r/model/advices_for_method'
4
3
  require 'aspect4r/model/aspect_data'
5
4
  require 'aspect4r/model/advice_metadata'
5
+ require 'aspect4r/model/method_matcher'
6
6
  require 'aspect4r/return_this'
7
7
 
8
8
  require 'aspect4r/helper'
@@ -10,43 +10,43 @@ require 'aspect4r/helper'
10
10
  module Aspect4r
11
11
  module Base
12
12
  def self.included(base)
13
- base.send(:include, InstanceMethods)
14
13
  base.extend(ClassMethods)
15
14
 
16
15
  eigen_class = class << base; self; end
17
- eigen_class.send(:include, InstanceMethods)
18
16
  eigen_class.extend(ClassMethods)
19
17
  end
20
18
 
21
- module InstanceMethods
22
- def a4r_invoke proxy, *args
23
- proxy.bind(self).call *args
24
- end
25
- end
26
-
27
19
  module ClassMethods
28
20
  def method_added method
29
21
  super method
30
22
 
31
- return if method.to_s[0..2] == "a4r"
23
+ return if Aspect4r::Helper.creating_method?
24
+
25
+ method = method.to_s
26
+ return if method[0..2] == "a4r"
32
27
 
33
28
  # save unbound method and create new method
34
- if method_advices = a4r_data[method] and not Aspect4r::Helper.creating_method?
35
- method_advices.wrapped_method = instance_method(method)
29
+ advices = a4r_data.advices_for_method(method)
30
+ unless advices.empty?
31
+ a4r_data.wrapped_methods[method] = instance_method(method)
36
32
  Aspect4r::Helper.create_method self, method
37
33
  end
38
34
  end
39
35
 
40
36
  def singleton_method_added method
41
37
  super method
38
+
39
+ return if Aspect4r::Helper.creating_method?
42
40
 
43
- return if method.to_s[0..2] == "a4r"
41
+ method = method.to_s
42
+ return if method[0..2] == "a4r"
44
43
 
45
44
  eigen_class = class << self; self; end
46
45
 
47
46
  # save unbound method and create new method
48
- if method_advices = eigen_class.a4r_data[method] and not Aspect4r::Helper.creating_method?
49
- method_advices.wrapped_method = eigen_class.instance_method(method)
47
+ advices = eigen_class.a4r_data.advices_for_method(method)
48
+ unless advices.empty?
49
+ eigen_class.a4r_data.wrapped_methods[method] = eigen_class.instance_method(method)
50
50
  Aspect4r::Helper.create_method eigen_class, method
51
51
  end
52
52
  end
@@ -66,20 +66,22 @@ module Aspect4r
66
66
 
67
67
  def a4r_disable_advices_temporarily *methods
68
68
  methods.each do |method|
69
- advices = a4r_data[method.to_sym]
70
- next if advices.nil? or advices.empty?
69
+ method = method.to_s
70
+ advices = a4r_data.advices_for_method(method)
71
+ next if advices.empty?
71
72
 
72
- Aspect4r::Helper.define_method self, method, advices.wrapped_method
73
+ send :alias_method, :"#{method}_with_advices", method
74
+ Aspect4r::Helper.define_method self, method, a4r_data.wrapped_methods[method]
73
75
  end
74
76
 
75
77
  yield
76
78
  ensure
77
79
  methods.each do |method|
78
- advices = a4r_data[method.to_sym]
79
-
80
- next if advices.nil? or advices.empty?
81
-
82
- Aspect4r::Helper.create_method self, method
80
+ method_with_advices = "#{method}_with_advices"
81
+ next unless instance_methods.include?(method_with_advices)
82
+
83
+ send :alias_method, method, method_with_advices
84
+ self.send :remove_method, method_with_advices
83
85
  end
84
86
  end
85
87
  end
@@ -27,7 +27,12 @@ module Aspect4r
27
27
  options = meta_data.default_options.clone
28
28
  options.merge!(methods.pop) if methods.last.is_a? Hash
29
29
  options.merge!(meta_data.mandatory_options)
30
-
30
+
31
+ # Convert symbols to strings to avoid inconsistencies
32
+ methods.size.times do |i|
33
+ methods[i] = methods[i].to_s if methods[i].is_a? Symbol
34
+ end
35
+
31
36
  if block_given?
32
37
  with_method = find_available_method_name klass_or_module, meta_data.with_method_prefix
33
38
  klass_or_module.send :define_method, with_method, &block
@@ -37,19 +42,24 @@ module Aspect4r
37
42
  end
38
43
 
39
44
  a4r_data = klass_or_module.a4r_data
40
- advice = Aspect4r::Model::Advice.new(meta_data.advice_type, with_method, a4r_data.group, options)
41
-
45
+ advice = Aspect4r::Model::Advice.new(meta_data.advice_type,
46
+ Aspect4r::Model::MethodMatcher.new(*methods),
47
+ with_method,
48
+ a4r_data.group,
49
+ options)
50
+ a4r_data << advice
51
+
42
52
  methods.each do |method|
43
- method = method.to_sym
53
+ next unless method.is_a? String
44
54
 
45
- aspect = a4r_data[method] ||= Aspect4r::Model::AdvicesForMethod.new(method)
46
- aspect.add advice
55
+ wrapped_method = a4r_data.wrapped_methods[method]
47
56
 
48
- if not aspect.wrapped_method and klass_or_module.instance_methods.include?(method.to_s)
49
- aspect.wrapped_method = klass_or_module.instance_method(method)
57
+ if not wrapped_method and klass_or_module.instance_methods.include?(method)
58
+ wrapped_method = klass_or_module.instance_method(method)
59
+ a4r_data.wrapped_methods[method] = wrapped_method
50
60
  end
51
61
 
52
- create_method klass_or_module, method if aspect.wrapped_method
62
+ create_method klass_or_module, method if wrapped_method
53
63
  end
54
64
  end
55
65
 
@@ -57,15 +67,14 @@ module Aspect4r
57
67
  def self.create_method klass, method
58
68
  @creating_method = true
59
69
 
60
- aspect = klass.a4r_data[method.to_sym]
61
-
62
- return if aspect.nil? or aspect.empty?
70
+ advices = klass.a4r_data.advices_for_method method
71
+ return if advices.empty?
63
72
 
64
73
  grouped_advices = []
65
74
  group = nil
66
75
  inner_most = true
67
76
 
68
- aspect.each do |advice|
77
+ advices.each do |advice|
69
78
  if ((group and group != advice.group) or advice.around?) and not grouped_advices.empty?
70
79
  create_method_with_advices klass, method, grouped_advices, inner_most
71
80
 
@@ -88,12 +97,12 @@ module Aspect4r
88
97
  # after_advices
89
98
  METHOD_TEMPLATE = ERB.new <<-CODE, nil, '<>'
90
99
  <% if inner_most %>
91
- wrapped_method = a4r_data[:<%= method %>].wrapped_method
100
+ wrapped_method = a4r_data.wrapped_methods['<%= method %>']
92
101
  <% else %>
93
102
  wrapped_method = instance_method(:<%= method %>)
94
103
  <% end %>
95
104
 
96
- define_method :<%= method %> do |*args|
105
+ define_method :<%= method %> do |*args, &block|
97
106
  result = nil
98
107
 
99
108
  # Before advices
@@ -112,10 +121,18 @@ module Aspect4r
112
121
 
113
122
  <% if around_advice %>
114
123
  # around advice
115
- result = <%= around_advice.with_method %> wrapped_method, *args
124
+ <% if around_advice.options[:method_name_arg] %>
125
+ result = <%= around_advice.with_method %> '<%= method %>', *args do |*args|
126
+ wrapped_method.bind(self).call *args, &block
127
+ end
128
+ <% else %>
129
+ result = <%= around_advice.with_method %> *args do |*args|
130
+ wrapped_method.bind(self).call *args, &block
131
+ end
132
+ <% end %>
116
133
  <% else %>
117
134
  # Invoke wrapped method
118
- result = wrapped_method.bind(self).call *args
135
+ result = wrapped_method.bind(self).call *args, &block
119
136
  <% end %>
120
137
 
121
138
  # After advices
@@ -6,10 +6,11 @@ module Aspect4r
6
6
  AROUND = 3
7
7
 
8
8
  attr :group
9
- attr_accessor :type, :with_method, :options
9
+ attr_accessor :type, :method_matcher, :with_method, :options
10
10
 
11
- def initialize type, with_method, group, options = {}
11
+ def initialize type, method_matcher, with_method, group, options = {}
12
12
  @type = type
13
+ @method_matcher = method_matcher
13
14
  @with_method = with_method
14
15
  @group = group
15
16
  @options = options
@@ -35,8 +36,32 @@ module Aspect4r
35
36
  type == AROUND
36
37
  end
37
38
 
38
- def invoke obj, *args
39
- obj.send with_method, *args
39
+ def invoke obj, *args, &block
40
+ obj.send with_method, *args, &block
41
+ end
42
+
43
+ def to_s
44
+ s = "<" << @group << "> "
45
+ case @type
46
+ when BEFORE
47
+ if @options[:skip_if_false]
48
+ s << "BEFORE_FILTER: "
49
+ else
50
+ s << "BEFORE: "
51
+ end
52
+ when AFTER
53
+ s << "AFTER : "
54
+ when AROUND
55
+ s << "AROUND: "
56
+ end
57
+ s << "[" << @method_matcher.to_s << "] DO "
58
+ s << @with_method.to_s
59
+ s << " WITH OPTIONS "
60
+ @options.each do |key, value|
61
+ next if key == :skip_if_false
62
+ s << key.to_s << ":" << value.to_s
63
+ end
64
+ s
40
65
  end
41
66
  end
42
67
  end
@@ -2,22 +2,31 @@ require 'set'
2
2
 
3
3
  module Aspect4r
4
4
  module Model
5
- class AspectData < Hash
5
+ class AspectData < Array
6
6
  def initialize klass_or_module
7
- @klass_or_module = klass_or_module
7
+ @group = klass_or_module.hash
8
8
  end
9
9
 
10
+ def wrapped_methods
11
+ @wrapped_methods ||= {}
12
+ end
13
+
10
14
  def group_index
11
15
  @group_index ||= 0
12
16
  end
13
-
17
+
14
18
  def group
15
- "#{@klass_or_module.hash}:#{group_index}"
19
+ "#{@group}:#{group_index}"
16
20
  end
17
-
21
+
18
22
  def change_group
19
23
  @group_index = group_index + 1
20
24
  end
25
+
26
+ def advices_for_method method
27
+ method = method.to_s
28
+ select {|advice| advice.method_matcher.match?(method) }
29
+ end
21
30
  end
22
31
  end
23
32
  end
@@ -0,0 +1,43 @@
1
+ module Aspect4r
2
+ module Model
3
+ class MethodMatcher
4
+ def initialize *match_data
5
+ @match_data = match_data
6
+
7
+ # Performance improvement ideas:
8
+ # if there is only one item in match_data, generate simplified match? method on the fly
9
+ # Seems this does not help much
10
+ #
11
+ # if match_data.size == 1
12
+ # first_item = match_data.first
13
+ # eigen_class = class << self; self; end
14
+ #
15
+ # if first_item.is_a? String
16
+ # eigen_class.send :define_method, :match? do |method|
17
+ # method == first_item
18
+ # end
19
+ # elsif first_item.is_a? Regexp
20
+ # eigen_class.send :define_method, :match? do |method|
21
+ # method =~ first_item
22
+ # end
23
+ # else
24
+ # eigen_class.send :define_method, :match? do |method|
25
+ # false
26
+ # end
27
+ # end
28
+ # end
29
+ end
30
+
31
+ def match? method
32
+ @match_data.detect do |item|
33
+ (item.is_a? String and item == method) or
34
+ (item.is_a? Regexp and item =~ method)
35
+ end
36
+ end
37
+
38
+ def to_s
39
+ @match_data.map {|item| item.inspect }.join ", "
40
+ end
41
+ end
42
+ end
43
+ end
@@ -11,9 +11,9 @@ describe "Advices on singleton method (also known as class method)" do
11
11
  @value ||= []
12
12
  end
13
13
 
14
- around :test do |proxy|
14
+ around :test do |&block|
15
15
  value << "around(before)"
16
- a4r_invoke proxy
16
+ block.call
17
17
  value << "around(after)"
18
18
  end
19
19
 
@@ -45,9 +45,9 @@ describe "Advices on singleton method (also known as class method)" do
45
45
  @value ||= []
46
46
  end
47
47
 
48
- around :test do |proxy|
48
+ around :test do |&block|
49
49
  value << "around(before)"
50
- a4r_invoke proxy
50
+ block.call
51
51
  value << "around(after)"
52
52
  end
53
53
 
@@ -11,9 +11,9 @@ describe "Test Advices" do
11
11
  @value = []
12
12
  end
13
13
 
14
- around :test do |proxy, input|
14
+ around :test do |input, &block|
15
15
  @value << "around(before)"
16
- a4r_invoke proxy, input
16
+ block.call input
17
17
  @value << "around(after)"
18
18
  end
19
19
 
@@ -38,33 +38,22 @@ describe "Test Advices" do
38
38
  end
39
39
 
40
40
  it "number of advices" do
41
- @klass.a4r_data[:test].size.should == 4
41
+ @klass.a4r_data.advices_for_method(:test).size.should == 4
42
42
  end
43
43
 
44
44
  it "around advice" do
45
- advice = @klass.a4r_data[:test][0]
45
+ advice = @klass.a4r_data.advices_for_method(:test)[0]
46
46
  advice.around?.should be_true
47
47
 
48
48
  o = @klass.new
49
- o.expects(:a4r_invoke).with(:proxy, 1)
50
49
 
51
- advice.invoke(o, :proxy, 1)
50
+ advice.invoke(o, 1) {}
52
51
 
53
52
  o.value.should == %w(around(before) around(after))
54
53
  end
55
54
 
56
55
  it "before advice" do
57
- advice = @klass.a4r_data[:test][1]
58
- advice.before?.should be_true
59
-
60
- o = @klass.new
61
- advice.invoke(o, 1)
62
-
63
- o.value.should == %w(before)
64
- end
65
-
66
- it "before advice retrieved by name" do
67
- advice = @klass.a4r_data[:test][:before_advice]
56
+ advice = @klass.a4r_data.advices_for_method(:test)[1]
68
57
  advice.before?.should be_true
69
58
 
70
59
  o = @klass.new
@@ -74,7 +63,7 @@ describe "Test Advices" do
74
63
  end
75
64
 
76
65
  it "before_filter advice returns true if input is not negative" do
77
- advice = @klass.a4r_data[:test][2]
66
+ advice = @klass.a4r_data.advices_for_method(:test)[2]
78
67
  advice.before_filter?.should be_true
79
68
 
80
69
  o = @klass.new
@@ -84,14 +73,14 @@ describe "Test Advices" do
84
73
  end
85
74
 
86
75
  it "before_filter advice returns false if input is negative" do
87
- advice = @klass.a4r_data[:test][2]
76
+ advice = @klass.a4r_data.advices_for_method(:test)[2]
88
77
 
89
78
  o = @klass.new
90
79
  advice.invoke(o, -1).should be_false
91
80
  end
92
81
 
93
82
  it "after advice" do
94
- advice = @klass.a4r_data[:test][3]
83
+ advice = @klass.a4r_data.advices_for_method(:test)[3]
95
84
  advice.after?.should be_true
96
85
 
97
86
  o = @klass.new