aquarium 0.4.3 → 0.4.4
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGES +322 -247
- data/README +11 -9
- data/Rakefile +22 -12
- data/UPGRADE +49 -43
- data/examples/aspect_design_example.rb +17 -14
- data/examples/design_by_contract_example.rb +14 -10
- data/examples/exception_wrapping_example.rb +5 -3
- data/examples/introductions_example.rb +2 -1
- data/examples/method_missing_example.rb +14 -13
- data/examples/method_tracing_example.rb +20 -16
- data/examples/reusable_aspect_hack_example.rb +8 -5
- data/lib/aquarium/aspects/exclusion_handler.rb +3 -3
- data/lib/aquarium/version.rb +1 -1
- data/rake_tasks/verify_rcov.rake +1 -1
- data/spec/aquarium/aspects/concurrent_aspects_spec.rb +41 -41
- data/spec/aquarium/aspects/join_point_spec.rb +5 -5
- data/spec/aquarium/aspects/pointcut_spec.rb +4 -1
- data/spec/aquarium/finders/type_finder_with_descendents_and_ancestors_spec.rb +4 -1
- metadata +3 -9
- data/Aquarium-IDEA.ipr +0 -252
- data/Aquarium-IDEA.iws +0 -493
- data/Aquarium.ipr +0 -253
- data/Aquarium.iws +0 -624
- data/ParseTreePlay.rb +0 -25
- data/TODO.rb +0 -186
@@ -1,6 +1,6 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
-
# Example demonstrating "around" advice that traces calls to all
|
3
|
-
# classes Foo and Bar
|
2
|
+
# Example demonstrating "around" advice that traces calls to all
|
3
|
+
# methods in classes Foo and Bar.
|
4
4
|
|
5
5
|
$LOAD_PATH.unshift File.dirname(__FILE__) + '/../lib'
|
6
6
|
require 'aquarium'
|
@@ -38,13 +38,16 @@ bar1.do_something_else :b3, :b4
|
|
38
38
|
|
39
39
|
include Aquarium::Aspects
|
40
40
|
|
41
|
-
|
42
|
-
|
41
|
+
# "jp" is the "join point", a.k.a. the current execution point.
|
42
|
+
Aspect.new :around, :calls_to => :all_methods,
|
43
|
+
:for_types => [Aquarium::Foo, Aquarium::Bar],
|
44
|
+
:method_options => :exclude_ancestor_methods do |jp, obj, *args|
|
43
45
|
begin
|
44
|
-
|
45
|
-
|
46
|
+
names = "#{jp.target_type.name}##{jp.method_name}"
|
47
|
+
p "Entering: #{names}: args = #{args.inspect}"
|
48
|
+
jp.proceed
|
46
49
|
ensure
|
47
|
-
p "Leaving: #{
|
50
|
+
p "Leaving: #{names}: args = #{args.inspect}"
|
48
51
|
end
|
49
52
|
end
|
50
53
|
|
@@ -55,15 +58,17 @@ foo2.do_it :b5, :b6
|
|
55
58
|
bar1 = Aquarium::Bar.new :a7, :a8
|
56
59
|
bar1.do_something_else :b7, :b8
|
57
60
|
|
58
|
-
# The "begin/ensure/end" idiom shown causes the advice to return the correct
|
59
|
-
# of the "proceed", rather than the value returned by "p"!
|
60
|
-
Aspect.new :around, :invocations_of => :initialize,
|
61
|
-
:
|
61
|
+
# The "begin/ensure/end" idiom shown causes the advice to return the correct
|
62
|
+
# value; the result of the "proceed", rather than the value returned by "p"!
|
63
|
+
Aspect.new :around, :invocations_of => :initialize,
|
64
|
+
:for_types => [Aquarium::Foo, Aquarium::Bar],
|
65
|
+
:restricting_methods_to => :private_methods do |jp, obj, *args|
|
62
66
|
begin
|
63
|
-
|
64
|
-
|
67
|
+
names = "#{jp.target_type.name}##{jp.method_name}"
|
68
|
+
p "Entering: #{names}: args = #{args.inspect}"
|
69
|
+
jp.proceed
|
65
70
|
ensure
|
66
|
-
p "Leaving: #{
|
71
|
+
p "Leaving: #{names}: args = #{args.inspect}"
|
67
72
|
end
|
68
73
|
end
|
69
74
|
|
@@ -72,5 +77,4 @@ foo2 = Aquarium::Foo.new :a9, :a10
|
|
72
77
|
foo2.do_it :b9, :b10
|
73
78
|
|
74
79
|
bar1 = Aquarium::Bar.new :a11, :a12
|
75
|
-
bar1.do_something_else :b11, :b12
|
76
|
-
|
80
|
+
bar1.do_something_else :b11, :b12
|
@@ -17,11 +17,13 @@ module Aquarium
|
|
17
17
|
module Reusables
|
18
18
|
module TraceMethods
|
19
19
|
def self.append_features mod
|
20
|
-
Aquarium::Aspects::Aspect.new :around,
|
21
|
-
:
|
22
|
-
|
20
|
+
Aquarium::Aspects::Aspect.new :around, :type => mod,
|
21
|
+
:methods => :all,
|
22
|
+
:method_options => [:exclude_ancestor_methods] do |jp, object, *args|
|
23
|
+
names = "#{jp.target_type.name}##{jp.method_name}"
|
24
|
+
p "Entering: #{names}: args = #{args.inspect}"
|
23
25
|
jp.proceed
|
24
|
-
p "Leaving:
|
26
|
+
p "Leaving: #{names}: args = #{args.inspect}"
|
25
27
|
end
|
26
28
|
end
|
27
29
|
end
|
@@ -32,7 +34,8 @@ class NotTraced1
|
|
32
34
|
def doit; p "NotTraced1#doit"; end
|
33
35
|
end
|
34
36
|
p "You will be warned that no join points in NotTraced2 were matched."
|
35
|
-
p "This happens because the include statement and hence the aspect evaluation
|
37
|
+
p "This happens because the include statement and hence the aspect evaluation"
|
38
|
+
p " happen BEFORE any methods are defined!"
|
36
39
|
class NotTraced2
|
37
40
|
include Aquarium::Reusables::TraceMethods
|
38
41
|
def doit; p "NotTraced2#doit"; end
|
@@ -42,9 +42,9 @@ module Aquarium
|
|
42
42
|
unless @specification[:exclude_types_calculated].nil?
|
43
43
|
return true if @specification[:exclude_types_calculated].find do |t|
|
44
44
|
case t
|
45
|
-
when String
|
46
|
-
when Symbol
|
47
|
-
when Regexp
|
45
|
+
when String then type_or_object.name.eql?(t)
|
46
|
+
when Symbol then type_or_object.name.eql?(t.to_s)
|
47
|
+
when Regexp then type_or_object.name =~ t
|
48
48
|
else type_or_object == t
|
49
49
|
end
|
50
50
|
end
|
data/lib/aquarium/version.rb
CHANGED
data/rake_tasks/verify_rcov.rake
CHANGED
@@ -116,84 +116,84 @@ describe "concurrent advice", :shared => true do
|
|
116
116
|
end
|
117
117
|
|
118
118
|
describe "Using two :before advices" do
|
119
|
-
|
119
|
+
before :each do
|
120
120
|
@advice_kinds = [:before, :before]
|
121
121
|
end
|
122
122
|
it_should_behave_like "concurrent advice"
|
123
123
|
end
|
124
124
|
|
125
125
|
describe "Using two :after advices" do
|
126
|
-
|
126
|
+
before :each do
|
127
127
|
@advice_kinds = [:after, :after]
|
128
128
|
end
|
129
129
|
it_should_behave_like "concurrent advice"
|
130
130
|
end
|
131
131
|
|
132
132
|
describe "Using two :after_returning advices" do
|
133
|
-
|
133
|
+
before :each do
|
134
134
|
@advice_kinds = [:after_returning, :after_returning]
|
135
135
|
end
|
136
136
|
it_should_behave_like "concurrent advice"
|
137
137
|
end
|
138
138
|
|
139
139
|
describe "Using two :after_raising advices" do
|
140
|
-
|
140
|
+
before :each do
|
141
141
|
@advice_kinds = [:after_raising, :after_raising]
|
142
142
|
end
|
143
143
|
it_should_behave_like "concurrent advice"
|
144
144
|
end
|
145
145
|
|
146
146
|
describe "Using two :around advices" do
|
147
|
-
|
147
|
+
before :each do
|
148
148
|
@advice_kinds = [:around, :around]
|
149
149
|
end
|
150
150
|
it_should_behave_like "concurrent advice"
|
151
151
|
end
|
152
152
|
|
153
153
|
describe "Using :before advice and :after advice" do
|
154
|
-
|
154
|
+
before :each do
|
155
155
|
@advice_kinds = [:before, :after]
|
156
156
|
end
|
157
157
|
it_should_behave_like "concurrent advice"
|
158
158
|
end
|
159
159
|
|
160
160
|
describe "Using :before advice and :after_returning advice" do
|
161
|
-
|
161
|
+
before :each do
|
162
162
|
@advice_kinds = [:before, :after_returning]
|
163
163
|
end
|
164
164
|
it_should_behave_like "concurrent advice"
|
165
165
|
end
|
166
166
|
|
167
167
|
describe "Using :before advice and :after_raising advice" do
|
168
|
-
|
168
|
+
before :each do
|
169
169
|
@advice_kinds = [:before, :after_raising]
|
170
170
|
end
|
171
171
|
it_should_behave_like "concurrent advice"
|
172
172
|
end
|
173
173
|
|
174
174
|
describe "Using :before advice and :around advice" do
|
175
|
-
|
175
|
+
before :each do
|
176
176
|
@advice_kinds = [:before, :around]
|
177
177
|
end
|
178
178
|
it_should_behave_like "concurrent advice"
|
179
179
|
end
|
180
180
|
|
181
181
|
describe "Using :after advice and :after_returning advice" do
|
182
|
-
|
182
|
+
before :each do
|
183
183
|
@advice_kinds = [:after, :after_returning]
|
184
184
|
end
|
185
185
|
it_should_behave_like "concurrent advice"
|
186
186
|
end
|
187
187
|
|
188
188
|
describe "Using :after advice and :after_raising advice" do
|
189
|
-
|
189
|
+
before :each do
|
190
190
|
@advice_kinds = [:after, :after_raising]
|
191
191
|
end
|
192
192
|
it_should_behave_like "concurrent advice"
|
193
193
|
end
|
194
194
|
|
195
195
|
describe "Using :after advice and :around advice" do
|
196
|
-
|
196
|
+
before :each do
|
197
197
|
@advice_kinds = [:after, :around]
|
198
198
|
end
|
199
199
|
it_should_behave_like "concurrent advice"
|
@@ -201,70 +201,70 @@ end
|
|
201
201
|
|
202
202
|
|
203
203
|
describe "Using :after_returning advice and :after_raising advice" do
|
204
|
-
|
204
|
+
before :each do
|
205
205
|
@advice_kinds = [:after_returning, :after_raising]
|
206
206
|
end
|
207
207
|
it_should_behave_like "concurrent advice"
|
208
208
|
end
|
209
209
|
|
210
210
|
describe "Using :after_returning advice and :around advice" do
|
211
|
-
|
211
|
+
before :each do
|
212
212
|
@advice_kinds = [:after_returning, :around]
|
213
213
|
end
|
214
214
|
it_should_behave_like "concurrent advice"
|
215
215
|
end
|
216
216
|
|
217
217
|
describe "Using :after_raising advice and :around advice" do
|
218
|
-
|
218
|
+
before :each do
|
219
219
|
@advice_kinds = [:after_raising, :around]
|
220
220
|
end
|
221
221
|
it_should_behave_like "concurrent advice"
|
222
222
|
end
|
223
223
|
|
224
224
|
describe "Using three :before advices" do
|
225
|
-
|
225
|
+
before :each do
|
226
226
|
3.times {|i| @advice_kinds[i] = :before}
|
227
227
|
end
|
228
228
|
it_should_behave_like "concurrent advice"
|
229
229
|
end
|
230
230
|
|
231
231
|
describe "Using three :before advices" do
|
232
|
-
|
232
|
+
before :each do
|
233
233
|
3.times {|i| @advice_kinds[i] = :before}
|
234
234
|
end
|
235
235
|
it_should_behave_like "concurrent advice"
|
236
236
|
end
|
237
237
|
|
238
238
|
describe "Using three :after advices" do
|
239
|
-
|
239
|
+
before :each do
|
240
240
|
3.times {|i| @advice_kinds[i] = :after}
|
241
241
|
end
|
242
242
|
it_should_behave_like "concurrent advice"
|
243
243
|
end
|
244
244
|
|
245
245
|
describe "Using three :after_returning advices" do
|
246
|
-
|
246
|
+
before :each do
|
247
247
|
3.times {|i| @advice_kinds[i] = :after_returning}
|
248
248
|
end
|
249
249
|
it_should_behave_like "concurrent advice"
|
250
250
|
end
|
251
251
|
|
252
252
|
describe "Using three :after_raising advices" do
|
253
|
-
|
253
|
+
before :each do
|
254
254
|
3.times {|i| @advice_kinds[i] = :after_raising}
|
255
255
|
end
|
256
256
|
it_should_behave_like "concurrent advice"
|
257
257
|
end
|
258
258
|
|
259
259
|
describe "Using three :around advices" do
|
260
|
-
|
260
|
+
before :each do
|
261
261
|
3.times {|i| @advice_kinds[i] = :around}
|
262
262
|
end
|
263
263
|
it_should_behave_like "concurrent advice"
|
264
264
|
end
|
265
265
|
|
266
266
|
describe "Using two :before advices and one :after advice" do
|
267
|
-
|
267
|
+
before :each do
|
268
268
|
2.times {|i| @advice_kinds[i] = :before}
|
269
269
|
@advice_kinds[2] = :after
|
270
270
|
end
|
@@ -272,7 +272,7 @@ describe "Using two :before advices and one :after advice" do
|
|
272
272
|
end
|
273
273
|
|
274
274
|
describe "Using two :before advices and one :after_returning advice" do
|
275
|
-
|
275
|
+
before :each do
|
276
276
|
2.times {|i| @advice_kinds[i] = :before}
|
277
277
|
@advice_kinds[2] = :after_returning
|
278
278
|
end
|
@@ -280,7 +280,7 @@ describe "Using two :before advices and one :after_returning advice" do
|
|
280
280
|
end
|
281
281
|
|
282
282
|
describe "Using two :before advices and one :after_raising advice" do
|
283
|
-
|
283
|
+
before :each do
|
284
284
|
2.times {|i| @advice_kinds[i] = :before}
|
285
285
|
@advice_kinds[2] = :after_raising
|
286
286
|
end
|
@@ -288,7 +288,7 @@ describe "Using two :before advices and one :after_raising advice" do
|
|
288
288
|
end
|
289
289
|
|
290
290
|
describe "Using two :before advices and one :around advice" do
|
291
|
-
|
291
|
+
before :each do
|
292
292
|
2.times {|i| @advice_kinds[i] = :before}
|
293
293
|
@advice_kinds[2] = :around
|
294
294
|
end
|
@@ -296,7 +296,7 @@ describe "Using two :before advices and one :around advice" do
|
|
296
296
|
end
|
297
297
|
|
298
298
|
describe "Using two :after advices and one :before advice" do
|
299
|
-
|
299
|
+
before :each do
|
300
300
|
2.times {|i| @advice_kinds[i] = :after}
|
301
301
|
@advice_kinds[2] = :before
|
302
302
|
end
|
@@ -304,7 +304,7 @@ describe "Using two :after advices and one :before advice" do
|
|
304
304
|
end
|
305
305
|
|
306
306
|
describe "Using two :after advices and one :after_returning advice" do
|
307
|
-
|
307
|
+
before :each do
|
308
308
|
2.times {|i| @advice_kinds[i] = :after}
|
309
309
|
@advice_kinds[2] = :after_returning
|
310
310
|
end
|
@@ -312,7 +312,7 @@ describe "Using two :after advices and one :after_returning advice" do
|
|
312
312
|
end
|
313
313
|
|
314
314
|
describe "Using two :after advices and one :after_raising advice" do
|
315
|
-
|
315
|
+
before :each do
|
316
316
|
2.times {|i| @advice_kinds[i] = :after}
|
317
317
|
@advice_kinds[2] = :after_raising
|
318
318
|
end
|
@@ -320,7 +320,7 @@ describe "Using two :after advices and one :after_raising advice" do
|
|
320
320
|
end
|
321
321
|
|
322
322
|
describe "Using two :after advices and one :around advice" do
|
323
|
-
|
323
|
+
before :each do
|
324
324
|
2.times {|i| @advice_kinds[i] = :after}
|
325
325
|
@advice_kinds[2] = :around
|
326
326
|
end
|
@@ -328,7 +328,7 @@ describe "Using two :after advices and one :around advice" do
|
|
328
328
|
end
|
329
329
|
|
330
330
|
describe "Using two :after_returning advices and one :before advice" do
|
331
|
-
|
331
|
+
before :each do
|
332
332
|
2.times {|i| @advice_kinds[i] = :after_returning}
|
333
333
|
@advice_kinds[2] = :before
|
334
334
|
end
|
@@ -336,7 +336,7 @@ describe "Using two :after_returning advices and one :before advice" do
|
|
336
336
|
end
|
337
337
|
|
338
338
|
describe "Using two :after_returning advices and one :after advice" do
|
339
|
-
|
339
|
+
before :each do
|
340
340
|
2.times {|i| @advice_kinds[i] = :after_returning}
|
341
341
|
@advice_kinds[2] = :after
|
342
342
|
end
|
@@ -344,7 +344,7 @@ describe "Using two :after_returning advices and one :after advice" do
|
|
344
344
|
end
|
345
345
|
|
346
346
|
describe "Using two :after_returning advices and one :after_raising advice" do
|
347
|
-
|
347
|
+
before :each do
|
348
348
|
2.times {|i| @advice_kinds[i] = :after_returning}
|
349
349
|
@advice_kinds[2] = :after_raising
|
350
350
|
end
|
@@ -352,7 +352,7 @@ describe "Using two :after_returning advices and one :after_raising advice" do
|
|
352
352
|
end
|
353
353
|
|
354
354
|
describe "Using two :after_returning advices and one :around advice" do
|
355
|
-
|
355
|
+
before :each do
|
356
356
|
2.times {|i| @advice_kinds[i] = :after_returning}
|
357
357
|
@advice_kinds[2] = :around
|
358
358
|
end
|
@@ -360,7 +360,7 @@ describe "Using two :after_returning advices and one :around advice" do
|
|
360
360
|
end
|
361
361
|
|
362
362
|
describe "Using two :after_raising advices and one :before advice" do
|
363
|
-
|
363
|
+
before :each do
|
364
364
|
2.times {|i| @advice_kinds[i] = :after_raising}
|
365
365
|
@advice_kinds[2] = :before
|
366
366
|
end
|
@@ -368,7 +368,7 @@ describe "Using two :after_raising advices and one :before advice" do
|
|
368
368
|
end
|
369
369
|
|
370
370
|
describe "Using two :after_raising advices and one :after advice" do
|
371
|
-
|
371
|
+
before :each do
|
372
372
|
2.times {|i| @advice_kinds[i] = :after_raising}
|
373
373
|
@advice_kinds[2] = :after
|
374
374
|
end
|
@@ -376,7 +376,7 @@ describe "Using two :after_raising advices and one :after advice" do
|
|
376
376
|
end
|
377
377
|
|
378
378
|
describe "Using two :after_raising advices and one :after_raising advice" do
|
379
|
-
|
379
|
+
before :each do
|
380
380
|
2.times {|i| @advice_kinds[i] = :after_raising}
|
381
381
|
@advice_kinds[2] = :after_raising
|
382
382
|
end
|
@@ -384,7 +384,7 @@ describe "Using two :after_raising advices and one :after_raising advice" do
|
|
384
384
|
end
|
385
385
|
|
386
386
|
describe "Using two :after_raising advices and one :around advice" do
|
387
|
-
|
387
|
+
before :each do
|
388
388
|
2.times {|i| @advice_kinds[i] = :after_raising}
|
389
389
|
@advice_kinds[2] = :around
|
390
390
|
end
|
@@ -392,7 +392,7 @@ describe "Using two :after_raising advices and one :around advice" do
|
|
392
392
|
end
|
393
393
|
|
394
394
|
describe "Using two :around advices and one :before advice" do
|
395
|
-
|
395
|
+
before :each do
|
396
396
|
2.times {|i| @advice_kinds[i] = :around}
|
397
397
|
@advice_kinds[2] = :before
|
398
398
|
end
|
@@ -400,7 +400,7 @@ describe "Using two :around advices and one :before advice" do
|
|
400
400
|
end
|
401
401
|
|
402
402
|
describe "Using two :around advices and one :after advice" do
|
403
|
-
|
403
|
+
before :each do
|
404
404
|
2.times {|i| @advice_kinds[i] = :around}
|
405
405
|
@advice_kinds[2] = :after
|
406
406
|
end
|
@@ -408,7 +408,7 @@ describe "Using two :around advices and one :after advice" do
|
|
408
408
|
end
|
409
409
|
|
410
410
|
describe "Using two :around advices and one :after_returning advice" do
|
411
|
-
|
411
|
+
before :each do
|
412
412
|
2.times {|i| @advice_kinds[i] = :around}
|
413
413
|
@advice_kinds[2] = :after_returning
|
414
414
|
end
|
@@ -416,7 +416,7 @@ describe "Using two :around advices and one :after_returning advice" do
|
|
416
416
|
end
|
417
417
|
|
418
418
|
describe "Using two :around advices and one :after_raising advice" do
|
419
|
-
|
419
|
+
before :each do
|
420
420
|
2.times {|i| @advice_kinds[i] = :around}
|
421
421
|
@advice_kinds[2] = :after_raising
|
422
422
|
end
|