aspector 0.7.0 → 0.7.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (47) hide show
  1. data/Gemfile +2 -2
  2. data/Gemfile.lock +6 -9
  3. data/README.rdoc +5 -4
  4. data/VERSION +1 -1
  5. data/aspector.gemspec +29 -20
  6. data/examples/activerecord_hooks.rb +2 -2
  7. data/examples/around_example.rb +1 -0
  8. data/examples/aspector_apply_example.rb +4 -3
  9. data/examples/aspector_example.rb +1 -0
  10. data/examples/cache_aspect.rb +2 -2
  11. data/examples/exception_handler.rb +36 -0
  12. data/examples/logging_aspect.rb +35 -0
  13. data/examples/retry_aspect.rb +41 -0
  14. data/lib/aspector/advice.rb +3 -7
  15. data/lib/aspector/base.rb +52 -29
  16. data/lib/aspector/context.rb +2 -1
  17. data/lib/aspector/deferred_logic.rb +3 -7
  18. data/lib/aspector/method_matcher.rb +6 -9
  19. data/performance-tests/after_test.rb +25 -0
  20. data/performance-tests/around_test.rb +27 -0
  21. data/performance-tests/before_test.rb +25 -0
  22. data/performance-tests/combined_test.rb +33 -0
  23. data/performance-tests/method_invocation_test.rb +25 -0
  24. data/performance-tests/test_helper.rb +9 -0
  25. data/spec/functional/advices_on_private_methods_spec.rb +21 -0
  26. data/spec/functional/aspect_on_eigen_class_spec.rb +66 -0
  27. data/spec/functional/aspect_on_object_spec.rb +20 -0
  28. data/spec/{aspector_spec.rb → functional/aspector_spec.rb} +13 -57
  29. data/spec/functional/aspects_combined_spec.rb +42 -0
  30. data/spec/functional/execution_order_spec.rb +36 -0
  31. data/spec/spec_helper.rb +16 -1
  32. data/spec/unit/advice_spec.rb +4 -0
  33. data/spec/{aspector → unit}/after_spec.rb +42 -38
  34. data/spec/{aspector → unit}/around_spec.rb +22 -18
  35. data/spec/unit/base_class_methods_spec.rb +28 -0
  36. data/spec/unit/base_spec.rb +81 -0
  37. data/spec/{aspector → unit}/before_spec.rb +27 -18
  38. data/spec/unit/deferred_logic_spec.rb +23 -0
  39. data/spec/unit/method_matcher_spec.rb +43 -0
  40. metadata +63 -69
  41. data/spec/advices_on_private_methods_spec.rb +0 -29
  42. data/spec/aspect_on_eigen_class_spec.rb +0 -86
  43. data/spec/aspect_on_object_spec.rb +0 -32
  44. data/spec/aspector/aspect_spec.rb +0 -86
  45. data/spec/aspector/base_spec.rb +0 -35
  46. data/spec/aspects_combined_spec.rb +0 -55
  47. data/spec/execution_order_spec.rb +0 -62
data/Gemfile CHANGED
@@ -2,13 +2,13 @@ source "http://rubygems.org"
2
2
 
3
3
  group :development do
4
4
  gem "rspec", "~> 2.3.0"
5
- gem "mocha", "~> 0.10.0"
6
- gem "bundler", "~> 1.0.0"
7
5
  gem "jeweler", "~> 1.6.4"
8
6
  gem "rcov", ">= 0"
9
7
  gem "reek", "~> 1.2.8"
10
8
  gem "roodi", "~> 2.1.0"
11
9
 
10
+ gem 'ruby-prof'
11
+
12
12
  gem "guard", "~> 0.8.4"
13
13
  gem "guard-bundler", "~> 0.1.3"
14
14
  gem "guard-rspec", "~> 0.5.2"
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  GEM
2
2
  remote: http://rubygems.org/
3
3
  specs:
4
- awesome_print (0.4.0)
4
+ awesome_print (1.0.2)
5
5
  diff-lcs (1.1.3)
6
6
  git (1.2.5)
7
7
  growl (1.0.3)
@@ -10,7 +10,7 @@ GEM
10
10
  guard-bundler (0.1.3)
11
11
  bundler (>= 1.0.0)
12
12
  guard (>= 0.2.2)
13
- guard-rspec (0.5.2)
13
+ guard-rspec (0.5.11)
14
14
  guard (>= 0.8.4)
15
15
  guard-shell (0.1.1)
16
16
  guard (>= 0.2.0)
@@ -18,12 +18,9 @@ GEM
18
18
  bundler (~> 1.0)
19
19
  git (>= 1.2.5)
20
20
  rake
21
- metaclass (0.0.1)
22
- mocha (0.10.0)
23
- metaclass (~> 0.0.1)
24
21
  rake (0.9.2.2)
25
22
  rb-fsevent (0.4.3.1)
26
- rcov (0.9.11)
23
+ rcov (1.0.0)
27
24
  reek (1.2.8)
28
25
  ruby2ruby (~> 1.2)
29
26
  ruby_parser (~> 2.0)
@@ -38,12 +35,13 @@ GEM
38
35
  rspec-expectations (2.3.0)
39
36
  diff-lcs (~> 1.1.2)
40
37
  rspec-mocks (2.3.0)
38
+ ruby-prof (0.10.8)
41
39
  ruby2ruby (1.3.1)
42
40
  ruby_parser (~> 2.0)
43
41
  sexp_processor (~> 3.0)
44
42
  ruby_parser (2.3.1)
45
43
  sexp_processor (~> 3.0)
46
- sexp_processor (3.0.7)
44
+ sexp_processor (3.0.10)
47
45
  thor (0.14.6)
48
46
 
49
47
  PLATFORMS
@@ -51,16 +49,15 @@ PLATFORMS
51
49
 
52
50
  DEPENDENCIES
53
51
  awesome_print
54
- bundler (~> 1.0.0)
55
52
  growl (~> 1.0.3)
56
53
  guard (~> 0.8.4)
57
54
  guard-bundler (~> 0.1.3)
58
55
  guard-rspec (~> 0.5.2)
59
56
  guard-shell (~> 0.1.1)
60
57
  jeweler (~> 1.6.4)
61
- mocha (~> 0.10.0)
62
58
  rb-fsevent (~> 0.4.3.1)
63
59
  rcov
64
60
  reek (~> 1.2.8)
65
61
  roodi (~> 2.1.0)
66
62
  rspec (~> 2.3.0)
63
+ ruby-prof
data/README.rdoc CHANGED
@@ -32,16 +32,17 @@ gem install aspector
32
32
  end
33
33
  end
34
34
 
35
- before :test, :do_this
36
- before :test do
35
+ before options[:method], :do_this
36
+
37
+ before options[:method] do
37
38
  puts 'do_that'
38
39
  end
39
40
  end
40
41
 
41
- TestAspect.apply(A)
42
-
43
42
  ##############################
44
43
 
44
+ TestAspect.apply A, :method => :test
45
+
45
46
  A.new.test
46
47
 
47
48
  # Expected output:
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.7.0
1
+ 0.7.1
data/aspector.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{aspector}
8
- s.version = "0.7.0"
8
+ s.version = "0.7.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-12-09}
12
+ s.date = %q{2012-02-09}
13
13
  s.description = %q{}
14
14
  s.email = %q{gcao99@gmail.com}
15
15
  s.extra_rdoc_files = [
@@ -34,6 +34,9 @@ Gem::Specification.new do |s|
34
34
  "examples/aspector_apply_example.rb",
35
35
  "examples/aspector_example.rb",
36
36
  "examples/cache_aspect.rb",
37
+ "examples/exception_handler.rb",
38
+ "examples/logging_aspect.rb",
39
+ "examples/retry_aspect.rb",
37
40
  "lib/aspector.rb",
38
41
  "lib/aspector/advice.rb",
39
42
  "lib/aspector/advice_metadata.rb",
@@ -47,18 +50,27 @@ Gem::Specification.new do |s|
47
50
  "lib/aspector/module_extension.rb",
48
51
  "lib/aspector/object_extension.rb",
49
52
  "lib/aspector/return_this.rb",
50
- "spec/advices_on_private_methods_spec.rb",
51
- "spec/aspect_on_eigen_class_spec.rb",
52
- "spec/aspect_on_object_spec.rb",
53
- "spec/aspector/after_spec.rb",
54
- "spec/aspector/around_spec.rb",
55
- "spec/aspector/aspect_spec.rb",
56
- "spec/aspector/base_spec.rb",
57
- "spec/aspector/before_spec.rb",
58
- "spec/aspector_spec.rb",
59
- "spec/aspects_combined_spec.rb",
60
- "spec/execution_order_spec.rb",
61
- "spec/spec_helper.rb"
53
+ "performance-tests/after_test.rb",
54
+ "performance-tests/around_test.rb",
55
+ "performance-tests/before_test.rb",
56
+ "performance-tests/combined_test.rb",
57
+ "performance-tests/method_invocation_test.rb",
58
+ "performance-tests/test_helper.rb",
59
+ "spec/functional/advices_on_private_methods_spec.rb",
60
+ "spec/functional/aspect_on_eigen_class_spec.rb",
61
+ "spec/functional/aspect_on_object_spec.rb",
62
+ "spec/functional/aspector_spec.rb",
63
+ "spec/functional/aspects_combined_spec.rb",
64
+ "spec/functional/execution_order_spec.rb",
65
+ "spec/spec_helper.rb",
66
+ "spec/unit/advice_spec.rb",
67
+ "spec/unit/after_spec.rb",
68
+ "spec/unit/around_spec.rb",
69
+ "spec/unit/base_class_methods_spec.rb",
70
+ "spec/unit/base_spec.rb",
71
+ "spec/unit/before_spec.rb",
72
+ "spec/unit/deferred_logic_spec.rb",
73
+ "spec/unit/method_matcher_spec.rb"
62
74
  ]
63
75
  s.homepage = %q{http://github.com/gcao/aspector}
64
76
  s.licenses = ["MIT"]
@@ -71,12 +83,11 @@ Gem::Specification.new do |s|
71
83
 
72
84
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
73
85
  s.add_development_dependency(%q<rspec>, ["~> 2.3.0"])
74
- s.add_development_dependency(%q<mocha>, ["~> 0.10.0"])
75
- s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
76
86
  s.add_development_dependency(%q<jeweler>, ["~> 1.6.4"])
77
87
  s.add_development_dependency(%q<rcov>, [">= 0"])
78
88
  s.add_development_dependency(%q<reek>, ["~> 1.2.8"])
79
89
  s.add_development_dependency(%q<roodi>, ["~> 2.1.0"])
90
+ s.add_development_dependency(%q<ruby-prof>, [">= 0"])
80
91
  s.add_development_dependency(%q<guard>, ["~> 0.8.4"])
81
92
  s.add_development_dependency(%q<guard-bundler>, ["~> 0.1.3"])
82
93
  s.add_development_dependency(%q<guard-rspec>, ["~> 0.5.2"])
@@ -86,12 +97,11 @@ Gem::Specification.new do |s|
86
97
  s.add_development_dependency(%q<awesome_print>, [">= 0"])
87
98
  else
88
99
  s.add_dependency(%q<rspec>, ["~> 2.3.0"])
89
- s.add_dependency(%q<mocha>, ["~> 0.10.0"])
90
- s.add_dependency(%q<bundler>, ["~> 1.0.0"])
91
100
  s.add_dependency(%q<jeweler>, ["~> 1.6.4"])
92
101
  s.add_dependency(%q<rcov>, [">= 0"])
93
102
  s.add_dependency(%q<reek>, ["~> 1.2.8"])
94
103
  s.add_dependency(%q<roodi>, ["~> 2.1.0"])
104
+ s.add_dependency(%q<ruby-prof>, [">= 0"])
95
105
  s.add_dependency(%q<guard>, ["~> 0.8.4"])
96
106
  s.add_dependency(%q<guard-bundler>, ["~> 0.1.3"])
97
107
  s.add_dependency(%q<guard-rspec>, ["~> 0.5.2"])
@@ -102,12 +112,11 @@ Gem::Specification.new do |s|
102
112
  end
103
113
  else
104
114
  s.add_dependency(%q<rspec>, ["~> 2.3.0"])
105
- s.add_dependency(%q<mocha>, ["~> 0.10.0"])
106
- s.add_dependency(%q<bundler>, ["~> 1.0.0"])
107
115
  s.add_dependency(%q<jeweler>, ["~> 1.6.4"])
108
116
  s.add_dependency(%q<rcov>, [">= 0"])
109
117
  s.add_dependency(%q<reek>, ["~> 1.2.8"])
110
118
  s.add_dependency(%q<roodi>, ["~> 2.1.0"])
119
+ s.add_dependency(%q<ruby-prof>, [">= 0"])
111
120
  s.add_dependency(%q<guard>, ["~> 0.8.4"])
112
121
  s.add_dependency(%q<guard-bundler>, ["~> 0.1.3"])
113
122
  s.add_dependency(%q<guard-rspec>, ["~> 0.5.2"])
@@ -26,10 +26,10 @@ class ActiveRecordHooks < Aspector::Base
26
26
  end
27
27
  end
28
28
 
29
- ActiveRecordHooks.apply(A)
30
-
31
29
  ##############################
32
30
 
31
+ ActiveRecordHooks.apply(A)
32
+
33
33
  a = A.new
34
34
  a.save
35
35
 
@@ -20,6 +20,7 @@ aspector(A) do
20
20
  end
21
21
 
22
22
  around :test, :do_this
23
+
23
24
  around :test do |&block|
24
25
  puts 'before(block)'
25
26
  block.call
@@ -10,7 +10,7 @@ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
10
10
 
11
11
  require 'aspector'
12
12
 
13
- TestAspect = Aspector do
13
+ aspect = Aspector do
14
14
  target do
15
15
  def do_this
16
16
  puts 'do_this'
@@ -18,15 +18,16 @@ TestAspect = Aspector do
18
18
  end
19
19
 
20
20
  before :test, :do_this
21
+
21
22
  before :test do
22
23
  puts 'do_that'
23
24
  end
24
25
  end
25
26
 
26
- TestAspect.apply(A)
27
-
28
27
  ##############################
29
28
 
29
+ aspect.apply(A)
30
+
30
31
  A.new.test
31
32
 
32
33
  # Expected output:
@@ -18,6 +18,7 @@ aspector(A) do
18
18
  end
19
19
 
20
20
  before :test, :do_this
21
+
21
22
  before :test do
22
23
  puts 'do_that'
23
24
  end
@@ -57,11 +57,11 @@ class CacheAspect < Aspector::Base
57
57
 
58
58
  end
59
59
 
60
+ ##############################
61
+
60
62
  CacheAspect.apply A, :method => :test, :ttl => 2 # 2 seconds
61
63
  CacheAspect.apply A, :method => :test2
62
64
 
63
- ##############################
64
-
65
65
  a = A.new
66
66
 
67
67
  # Will store value in cache
@@ -0,0 +1,36 @@
1
+ class A
2
+
3
+ def test input
4
+ puts input.upcase
5
+ end
6
+
7
+ end
8
+
9
+ ##############################
10
+
11
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
12
+
13
+ require 'aspector'
14
+
15
+ class ExceptionHandler < Aspector::Base
16
+
17
+ target do
18
+ def handle_exception *args, &block
19
+ block.call *args
20
+ rescue => e
21
+ puts "Rescued: #{e}"
22
+ end
23
+ end
24
+
25
+ around options[:method], :handle_exception
26
+
27
+ end
28
+
29
+ ##############################
30
+
31
+ ExceptionHandler.apply(A, :method => :test)
32
+
33
+ a = A.new
34
+ a.test 'good'
35
+ a.test nil
36
+
@@ -0,0 +1,35 @@
1
+ class A
2
+
3
+ def test input
4
+ input.upcase
5
+ end
6
+
7
+ end
8
+
9
+ ##############################
10
+
11
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
12
+
13
+ require 'aspector'
14
+
15
+ class LoggingAspect < Aspector::Base
16
+
17
+ ALL_METHODS = /.*/
18
+
19
+ around ALL_METHODS, :except => :class, :method_name_arg => true do |method, *args, &block|
20
+ class_method = "#{self.class}.#{method}"
21
+ puts "Entering #{class_method}: #{args.join(',')}"
22
+ result = block.call *args
23
+ puts "Exiting #{class_method}: #{result}"
24
+ result
25
+ end
26
+
27
+ end
28
+
29
+ ##############################
30
+
31
+ LoggingAspect.apply(A)
32
+
33
+ a = A.new
34
+ a.test 'input'
35
+
@@ -0,0 +1,41 @@
1
+ class A
2
+
3
+ def test
4
+ puts 'test'
5
+ raise
6
+ end
7
+
8
+ end
9
+
10
+ ##############################
11
+
12
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
13
+
14
+ require 'aspector'
15
+
16
+ class RetryAspect < Aspector::Base
17
+
18
+ target do
19
+ def retry_this &block
20
+ block.call
21
+ rescue => e
22
+ @retry_count ||= 3
23
+ @retry_count -= 1
24
+
25
+ @retry_count = nil or raise if @retry_count == 0
26
+
27
+ retry
28
+ end
29
+ end
30
+
31
+ around options[:method], :retry_this
32
+
33
+ end
34
+
35
+ ##############################
36
+
37
+ RetryAspect.apply(A, :method => :test)
38
+
39
+ a = A.new
40
+ a.test
41
+
@@ -13,7 +13,7 @@ module Aspector
13
13
  @method_matcher = method_matcher
14
14
  @with_method = with_method
15
15
  @options = options
16
- @advice_block = block.to_proc if block_given?
16
+ @advice_block = block
17
17
  end
18
18
 
19
19
  def with_method
@@ -26,17 +26,13 @@ module Aspector
26
26
 
27
27
  return true unless @options[:except]
28
28
 
29
- @except ||= MethodMatcher.new([@options[:except]].flatten)
29
+ @except ||= MethodMatcher.new(@options[:except])
30
30
 
31
31
  not @except.match?(method)
32
32
  end
33
33
 
34
34
  def before?
35
- type == BEFORE and not options[:skip_if_false]
36
- end
37
-
38
- def before_filter?
39
- type == BEFORE and options[:skip_if_false]
35
+ type == BEFORE
40
36
  end
41
37
 
42
38
  def after?
data/lib/aspector/base.rb CHANGED
@@ -18,7 +18,7 @@ module Aspector
18
18
  # @context is where advices will be applied (i.e. where methods are modified), can be different from target
19
19
  @context = get_context
20
20
 
21
- after_initialization
21
+ after_initialize
22
22
  end
23
23
 
24
24
  def apply
@@ -27,7 +27,7 @@ module Aspector
27
27
  add_to_instances
28
28
  apply_to_methods
29
29
  add_method_hooks
30
- after_application
30
+ after_apply
31
31
  end
32
32
 
33
33
  def deferred_logic_results logic
@@ -69,11 +69,11 @@ module Aspector
69
69
  protected
70
70
 
71
71
  # Hook method that runs after an aspect is instantiated
72
- def after_initialization
72
+ def after_initialize
73
73
  end
74
74
 
75
75
  # Hook method that runs after an aspect is applied
76
- def after_application
76
+ def after_apply
77
77
  end
78
78
 
79
79
  private
@@ -91,7 +91,7 @@ module Aspector
91
91
 
92
92
  @deferred_logic_results ||= {}
93
93
  self.class.deferred_logics.each do |logic|
94
- @deferred_logic_results[logic] = logic.apply @context
94
+ @deferred_logic_results[logic] = logic.apply @context, self
95
95
  end
96
96
  end
97
97
 
@@ -150,8 +150,8 @@ module Aspector
150
150
  def recreate_method method, advices, scope
151
151
  @context.instance_variable_set(:@aspector_creating_method, true)
152
152
 
153
- before_advices = advices.select {|advice| advice.before? or advice.before_filter? }
154
- after_advices = advices.select {|advice| advice.after? }
153
+ before_advices = advices.select {|advice| advice.before? }
154
+ after_advices = advices.select {|advice| advice.after? }
155
155
  around_advices = advices.select {|advice| advice.around? }
156
156
 
157
157
  if around_advices.size > 1
@@ -179,57 +179,80 @@ module Aspector
179
179
  wrapped_method = instance_method(:<%= method %>)
180
180
 
181
181
  define_method :<%= method %> do |*args, &block|
182
- result = nil
183
-
184
182
  # Before advices
185
- <% before_advices.each do |advice| %>
186
- <% if advice.options[:context_arg] %>
183
+ <% before_advices.each do |advice|
184
+ if advice.options[:context_arg]
185
+ %>
187
186
  context = Aspector::Context.new(target, <%= self.hash %>, <%= advice.hash %>)
188
187
  context.method_name = '<%= method %>'
189
188
  result = <%= advice.with_method %> context, *args
190
- <% else %>
189
+ <% elsif advice.options[:method_name_arg] %>
190
+ result = <%= advice.with_method %> '<%= method %>', *args
191
+ <% else %>
191
192
  result = <%= advice.with_method %> *args
192
- <% end %>
193
+ <% end %>
193
194
 
194
195
  return result.value if result.is_a? ::Aspector::ReturnThis
195
- <% if advice.options[:skip_if_false] %>
196
+ <% if advice.options[:skip_if_false] %>
196
197
  return unless result
197
- <% end %>
198
- <% end %>
198
+ <% end
199
+ end
200
+ %>
199
201
 
200
- <% if around_advice %>
201
- # around advice
202
- <% if around_advice.options[:context_arg] %>
202
+ <% if around_advice
203
+ if around_advice.options[:context_arg]
204
+ %>
203
205
  context = Aspector::Context.new(target, <%= self.hash %>, <%= around_advice.hash %>)
204
206
  context.method_name = '<%= method %>'
205
207
  result = <%= around_advice.with_method %> context, *args do |*args|
206
208
  wrapped_method.bind(self).call *args, &block
207
209
  end
208
- <% else %>
210
+ <% elsif around_advice.options[:method_name_arg] %>
211
+ result = <%= around_advice.with_method %> '<%= method %>', *args do |*args|
212
+ wrapped_method.bind(self).call *args, &block
213
+ end
214
+ <% else %>
209
215
  result = <%= around_advice.with_method %> *args do |*args|
210
216
  wrapped_method.bind(self).call *args, &block
211
217
  end
212
- <% end %>
213
- <% else %>
218
+ <% end
219
+ else
220
+ %>
214
221
  # Invoke wrapped method
215
222
  result = wrapped_method.bind(self).call *args, &block
216
223
  <% end %>
217
224
 
218
225
  # After advices
219
- <% after_advices.each do |advice| %>
220
- <% if advice.options[:context_arg] and advice.options[:result_arg] %>
226
+ <% unless after_advices.empty?
227
+ after_advices.each do |advice|
228
+ if advice.options[:context_arg]
229
+ if advice.options[:result_arg]
230
+ %>
221
231
  context = Aspector::Context.new(target, <%= self.hash %>, <%= advice.hash %>)
222
232
  context.method_name = '<%= method %>'
223
233
  result = <%= advice.with_method %> context, result, *args
224
- <% elsif advice.options[:context_arg] %>
234
+ <% else %>
225
235
  <%= advice.with_method %> context, *args
226
- <% elsif advice.options[:result_arg] %>
236
+ <% end
237
+ elsif advice.options[:method_name_arg]
238
+ if advice.options[:result_arg]
239
+ %>
240
+ result = <%= advice.with_method %> '<%= method %>', result, *args
241
+ <% else %>
242
+ <%= advice.with_method %> '<%= method %>', *args
243
+ <% end
244
+ else
245
+ if advice.options[:result_arg]
246
+ %>
227
247
  result = <%= advice.with_method %> result, *args
228
- <% else %>
248
+ <% else %>
229
249
  <%= advice.with_method %> *args
230
- <% end %>
231
- <% end %>
250
+ <% end
251
+ end
252
+ end
253
+ %>
232
254
  result
255
+ <% end %>
233
256
  end
234
257
  CODE
235
258
 
@@ -1,10 +1,11 @@
1
1
  module Aspector
2
2
  class Context
3
3
 
4
+ attr :target
4
5
  attr_accessor :method_name
5
6
 
6
7
  def initialize(target, aspect_hash, advice_hash)
7
- @target = target
8
+ @target = target
8
9
  @aspect_hash = aspect_hash
9
10
  @advice_hash = advice_hash
10
11
  end
@@ -1,18 +1,14 @@
1
1
  module Aspector
2
2
  class DeferredLogic
3
3
 
4
- attr_reader :code, :value
4
+ attr_reader :code
5
5
 
6
6
  def initialize code
7
7
  @code = code
8
8
  end
9
9
 
10
- def apply target
11
- if @code.is_a? String
12
- @value = target.class_eval(@code)
13
- else
14
- @value = target.class_eval(&@code)
15
- end
10
+ def apply target, *args
11
+ target.class_exec(*args, &@code)
16
12
  end
17
13
 
18
14
  end
@@ -2,9 +2,10 @@ module Aspector
2
2
  class MethodMatcher
3
3
  def initialize *match_data
4
4
  @match_data = match_data
5
+ @match_data.flatten!
5
6
  end
6
7
 
7
- def match? method, context = nil
8
+ def match? method, aspect = nil
8
9
  @match_data.detect do |item|
9
10
  case item
10
11
  when String
@@ -14,25 +15,21 @@ module Aspector
14
15
  when Symbol
15
16
  item.to_s == method
16
17
  when DeferredLogic
17
- value = context.deferred_logic_results[item]
18
+ value = aspect.deferred_logic_results(item)
18
19
  if value
19
- new_matcher = MethodMatcher.new(*[value].flatten)
20
+ new_matcher = MethodMatcher.new(value)
20
21
  new_matcher.match?(method)
21
22
  end
22
23
  when DeferredOption
23
- value = context.options[item.key]
24
+ value = aspect.options[item.key]
24
25
  if value
25
- new_matcher = MethodMatcher.new(*[value].flatten)
26
+ new_matcher = MethodMatcher.new(value)
26
27
  new_matcher.match?(method)
27
28
  end
28
29
  end
29
30
  end
30
31
  end
31
32
 
32
- def has_regular_expressions?
33
- @has_regexps ||= @match_data.detect { |item| item.is_a? Regexp }
34
- end
35
-
36
33
  def to_s
37
34
  @match_data.map {|item| item.inspect }.join ", "
38
35
  end