aspector 0.8.0 → 0.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/VERSION +1 -1
- data/aspector.gemspec +3 -3
- data/examples/around_example.rb +10 -6
- data/examples/cache_aspect.rb +2 -2
- data/examples/exception_handler.rb +2 -2
- data/examples/logging_aspect.rb +11 -2
- data/examples/retry_aspect.rb +2 -2
- data/lib/aspector/aspect_instances.rb +1 -1
- data/lib/aspector/base.rb +72 -57
- data/lib/aspector/base_class_methods.rb +15 -0
- data/lib/aspector/module_extension.rb +11 -11
- data/lib/aspector/object_extension.rb +8 -0
- data/lib/aspector.rb +0 -1
- data/performance-tests/around_advice_benchmark.rb +65 -0
- data/performance-tests/around_test.rb +2 -2
- data/spec/functional/aspect_on_eigen_class_spec.rb +4 -4
- data/spec/functional/aspector_spec.rb +4 -4
- data/spec/functional/aspects_combined_spec.rb +4 -4
- data/spec/functional/execution_order_spec.rb +4 -4
- data/spec/unit/around_spec.rb +6 -6
- metadata +159 -100
- data/lib/aspector/return_this.rb +0 -9
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.9.0
|
data/aspector.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = "aspector"
|
8
|
-
s.version = "0.
|
8
|
+
s.version = "0.9.0"
|
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 = "2012-
|
12
|
+
s.date = "2012-03-08"
|
13
13
|
s.description = ""
|
14
14
|
s.email = "gcao99@gmail.com"
|
15
15
|
s.extra_rdoc_files = [
|
@@ -48,8 +48,8 @@ Gem::Specification.new do |s|
|
|
48
48
|
"lib/aspector/method_matcher.rb",
|
49
49
|
"lib/aspector/module_extension.rb",
|
50
50
|
"lib/aspector/object_extension.rb",
|
51
|
-
"lib/aspector/return_this.rb",
|
52
51
|
"performance-tests/after_test.rb",
|
52
|
+
"performance-tests/around_advice_benchmark.rb",
|
53
53
|
"performance-tests/around_test.rb",
|
54
54
|
"performance-tests/before_test.rb",
|
55
55
|
"performance-tests/combined_test.rb",
|
data/examples/around_example.rb
CHANGED
@@ -1,6 +1,8 @@
|
|
1
1
|
class A
|
2
2
|
def test
|
3
|
-
puts 'test'
|
3
|
+
puts 'test 1'
|
4
|
+
yield
|
5
|
+
puts 'test 2'
|
4
6
|
end
|
5
7
|
end
|
6
8
|
|
@@ -12,25 +14,27 @@ require 'aspector'
|
|
12
14
|
|
13
15
|
aspector(A) do
|
14
16
|
target do
|
15
|
-
def do_this &block
|
17
|
+
def do_this proxy, &block
|
16
18
|
puts 'before'
|
17
|
-
|
19
|
+
proxy.call &block
|
18
20
|
puts 'after'
|
19
21
|
end
|
20
22
|
end
|
21
23
|
|
22
24
|
around :test, :do_this
|
23
25
|
|
24
|
-
around :test do
|
26
|
+
around :test do |proxy, &block|
|
25
27
|
puts 'before(block)'
|
26
|
-
|
28
|
+
proxy.call &block
|
27
29
|
puts 'after(block)'
|
28
30
|
end
|
29
31
|
end
|
30
32
|
|
31
33
|
##############################
|
32
34
|
|
33
|
-
A.new.test
|
35
|
+
A.new.test do
|
36
|
+
puts 'in block'
|
37
|
+
end
|
34
38
|
|
35
39
|
# Expected output:
|
36
40
|
# before
|
data/examples/cache_aspect.rb
CHANGED
@@ -48,12 +48,12 @@ class CacheAspect < Aspector::Base
|
|
48
48
|
|
49
49
|
def after_initialize
|
50
50
|
aspect = self
|
51
|
-
around options[:method], :method_name_arg => true do |method, &block|
|
51
|
+
around options[:method], :method_name_arg => true do |method, proxy, &block|
|
52
52
|
key = method
|
53
53
|
ttl = aspect.options[:ttl]
|
54
54
|
|
55
55
|
SimpleCache.cache key, ttl do
|
56
|
-
|
56
|
+
proxy.call &block
|
57
57
|
end
|
58
58
|
end
|
59
59
|
end
|
data/examples/logging_aspect.rb
CHANGED
@@ -16,10 +16,10 @@ class LoggingAspect < Aspector::Base
|
|
16
16
|
|
17
17
|
ALL_METHODS = /.*/
|
18
18
|
|
19
|
-
around ALL_METHODS, :except => :class, :method_name_arg => true do |method, *args, &block|
|
19
|
+
around ALL_METHODS, :except => :class, :method_name_arg => true do |method, proxy, *args, &block|
|
20
20
|
class_method = "#{self.class}.#{method}"
|
21
21
|
puts "Entering #{class_method}: #{args.join(',')}"
|
22
|
-
result =
|
22
|
+
result = proxy.call *args, &block
|
23
23
|
puts "Exiting #{class_method}: #{result}"
|
24
24
|
result
|
25
25
|
end
|
@@ -29,7 +29,16 @@ end
|
|
29
29
|
##############################
|
30
30
|
|
31
31
|
LoggingAspect.apply(A)
|
32
|
+
puts "LoggingAspect is applied"
|
32
33
|
|
33
34
|
a = A.new
|
34
35
|
a.test 'input'
|
35
36
|
|
37
|
+
LoggingAspect.disable
|
38
|
+
puts "LoggingAspect is disabled"
|
39
|
+
a.test 'input'
|
40
|
+
|
41
|
+
LoggingAspect.enable
|
42
|
+
puts "LoggingAspect is enabled"
|
43
|
+
a.test 'input'
|
44
|
+
|
data/examples/retry_aspect.rb
CHANGED
data/lib/aspector/base.rb
CHANGED
@@ -6,6 +6,8 @@ module Aspector
|
|
6
6
|
attr :aop_options
|
7
7
|
alias :options :aop_options
|
8
8
|
|
9
|
+
attr :aop_wrapped_methods
|
10
|
+
|
9
11
|
def initialize target, options = {}
|
10
12
|
@aop_target = target
|
11
13
|
|
@@ -19,6 +21,8 @@ module Aspector
|
|
19
21
|
# @aop_context is where advices will be applied (i.e. where methods are modified), can be different from target
|
20
22
|
@aop_context = aop_get_context
|
21
23
|
|
24
|
+
@aop_wrapped_methods = {}
|
25
|
+
|
22
26
|
after_initialize
|
23
27
|
end
|
24
28
|
|
@@ -47,6 +51,43 @@ module Aspector
|
|
47
51
|
end
|
48
52
|
alias :apply :aop_apply
|
49
53
|
|
54
|
+
def aop_apply_to_methods
|
55
|
+
advices = aop_advices
|
56
|
+
@aop_context.public_instance_methods.each do |method|
|
57
|
+
aop_apply_to_method(method.to_s, advices, :public)
|
58
|
+
end
|
59
|
+
|
60
|
+
@aop_context.protected_instance_methods.each do |method|
|
61
|
+
aop_apply_to_method(method.to_s, advices, :protected)
|
62
|
+
end
|
63
|
+
|
64
|
+
if @aop_options[:private_methods]
|
65
|
+
@aop_context.private_instance_methods.each do |method|
|
66
|
+
aop_apply_to_method(method.to_s, advices, :private)
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
def aop_apply_to_method method, advices, scope = nil
|
72
|
+
advices = aop_filter_advices advices, method
|
73
|
+
return if advices.empty?
|
74
|
+
|
75
|
+
before_apply_to_method method, advices
|
76
|
+
|
77
|
+
scope ||=
|
78
|
+
if @aop_context.private_instance_methods.include?(RUBY_VERSION.index('1.9') ? method.to_sym : method.to_s)
|
79
|
+
:private
|
80
|
+
elsif @aop_context.protected_instance_methods.include?(RUBY_VERSION.index('1.9') ? method.to_sym : method.to_s)
|
81
|
+
:protected
|
82
|
+
else
|
83
|
+
:public
|
84
|
+
end
|
85
|
+
|
86
|
+
aop_recreate_method method, advices, scope
|
87
|
+
|
88
|
+
after_apply_to_method method, advices
|
89
|
+
end
|
90
|
+
|
50
91
|
protected
|
51
92
|
|
52
93
|
# Hook method that runs after an aspect is instantiated
|
@@ -97,42 +138,6 @@ module Aspector
|
|
97
138
|
@aop_deferred_logic_results[logic]
|
98
139
|
end
|
99
140
|
|
100
|
-
def aop_apply_to_methods
|
101
|
-
@aop_context.public_instance_methods.each do |method|
|
102
|
-
aop_apply_to_method(method.to_s, :public)
|
103
|
-
end
|
104
|
-
|
105
|
-
@aop_context.protected_instance_methods.each do |method|
|
106
|
-
aop_apply_to_method(method.to_s, :protected)
|
107
|
-
end
|
108
|
-
|
109
|
-
if @aop_options[:private_methods]
|
110
|
-
@aop_context.private_instance_methods.each do |method|
|
111
|
-
aop_apply_to_method(method.to_s, :private)
|
112
|
-
end
|
113
|
-
end
|
114
|
-
end
|
115
|
-
|
116
|
-
def aop_apply_to_method method, scope = nil
|
117
|
-
advices = aop_advices_for_method method
|
118
|
-
return if advices.empty?
|
119
|
-
|
120
|
-
before_apply_to_method method, advices
|
121
|
-
|
122
|
-
scope ||=
|
123
|
-
if @aop_context.private_instance_methods.include?(RUBY_VERSION.index('1.9') ? method.to_sym : method.to_s)
|
124
|
-
:private
|
125
|
-
elsif @aop_context.protected_instance_methods.include?(RUBY_VERSION.index('1.9') ? method.to_sym : method.to_s)
|
126
|
-
:protected
|
127
|
-
else
|
128
|
-
:public
|
129
|
-
end
|
130
|
-
|
131
|
-
aop_recreate_method method, advices, scope
|
132
|
-
|
133
|
-
after_apply_to_method method, advices
|
134
|
-
end
|
135
|
-
|
136
141
|
def aop_get_context
|
137
142
|
return @aop_target if @aop_target.is_a?(Module) and not @aop_options[:eigen_class]
|
138
143
|
|
@@ -196,44 +201,54 @@ module Aspector
|
|
196
201
|
end
|
197
202
|
end
|
198
203
|
|
199
|
-
def
|
200
|
-
|
204
|
+
def aop_filter_advices advices, method
|
205
|
+
advices.select do |advice|
|
201
206
|
advice.match?(method, self)
|
202
207
|
end
|
203
208
|
end
|
204
209
|
|
205
210
|
def aop_recreate_method method, advices, scope
|
211
|
+
@aop_wrapped_methods[method] = @aop_context.instance_method(method)
|
206
212
|
@aop_context.instance_variable_set(:@aop_creating_method, true)
|
207
213
|
|
208
214
|
before_advices = advices.select {|advice| advice.before? }
|
209
215
|
after_advices = advices.select {|advice| advice.after? }
|
210
216
|
around_advices = advices.select {|advice| advice.around? }
|
211
217
|
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
aop_recreate_method_with_advices method, [], [], advice
|
216
|
-
end
|
218
|
+
(around_advices.size - 1).downto(1) do |i|
|
219
|
+
advice = around_advices[i]
|
220
|
+
aop_recreate_method_with_advices method, [], [], advice
|
217
221
|
end
|
218
222
|
|
219
|
-
aop_recreate_method_with_advices method, before_advices, after_advices, around_advices.first
|
223
|
+
aop_recreate_method_with_advices method, before_advices, after_advices, around_advices.first, true
|
220
224
|
|
221
225
|
@aop_context.send scope, method if scope != :public
|
222
226
|
ensure
|
223
227
|
@aop_context.instance_variable_set(:@aop_creating_method, nil)
|
224
228
|
end
|
225
229
|
|
226
|
-
def aop_recreate_method_with_advices method, before_advices, after_advices, around_advice
|
230
|
+
def aop_recreate_method_with_advices method, before_advices, after_advices, around_advice, is_outermost = false
|
231
|
+
aspect = self
|
232
|
+
|
227
233
|
code = METHOD_TEMPLATE.result(binding)
|
228
234
|
#puts code
|
229
235
|
@aop_context.class_eval code, __FILE__, __LINE__ + 4
|
230
236
|
end
|
231
237
|
|
232
238
|
METHOD_TEMPLATE = ERB.new <<-CODE
|
233
|
-
|
239
|
+
orig_method = aspect.aop_wrapped_methods['<%= method %>']
|
240
|
+
|
241
|
+
<% if around_advice %>
|
234
242
|
wrapped_method = instance_method(:<%= method %>)
|
243
|
+
<% end %>
|
235
244
|
|
236
245
|
define_method :<%= method %> do |*args, &block|
|
246
|
+
return orig_method.bind(self).call(*args, &block) if aspect.class.aop_disabled?
|
247
|
+
|
248
|
+
<% if is_outermost %>
|
249
|
+
catch(:aop_return) do
|
250
|
+
<% end %>
|
251
|
+
|
237
252
|
# Before advices
|
238
253
|
<% before_advices.each do |advice|
|
239
254
|
if advice.options[:method_name_arg] %>
|
@@ -242,27 +257,23 @@ module Aspector
|
|
242
257
|
result = <%= advice.with_method %> *args
|
243
258
|
<% end %>
|
244
259
|
|
245
|
-
return result.value if result.is_a? ::Aspector::ReturnThis
|
246
260
|
<% if advice.options[:skip_if_false] %>
|
247
261
|
return unless result
|
248
262
|
<% end
|
249
263
|
end
|
250
264
|
%>
|
251
265
|
|
252
|
-
<% if around_advice
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
end
|
266
|
+
<% if around_advice %>
|
267
|
+
# Around advice
|
268
|
+
<% if around_advice.options[:method_name_arg] %>
|
269
|
+
result = <%= around_advice.with_method %> '<%= method %>', wrapped_method.bind(self), *args, &block
|
257
270
|
<% else %>
|
258
|
-
result = <%= around_advice.with_method %> *args
|
259
|
-
wrapped_method.bind(self).call *args, &block
|
260
|
-
end
|
271
|
+
result = <%= around_advice.with_method %> wrapped_method.bind(self), *args, &block
|
261
272
|
<% end
|
262
273
|
else
|
263
274
|
%>
|
264
|
-
# Invoke
|
265
|
-
result =
|
275
|
+
# Invoke original method
|
276
|
+
result = orig_method.bind(self).call *args, &block
|
266
277
|
<% end %>
|
267
278
|
|
268
279
|
# After advices
|
@@ -285,6 +296,10 @@ module Aspector
|
|
285
296
|
%>
|
286
297
|
result
|
287
298
|
<% end %>
|
299
|
+
|
300
|
+
<% if is_outermost %>
|
301
|
+
end
|
302
|
+
<% end %>
|
288
303
|
end
|
289
304
|
CODE
|
290
305
|
|
@@ -3,6 +3,21 @@ module Aspector
|
|
3
3
|
module ClassMethods
|
4
4
|
::Aspector::Base.extend(self)
|
5
5
|
|
6
|
+
def aop_enable
|
7
|
+
@aop_disabled = nil
|
8
|
+
end
|
9
|
+
alias :enable :aop_enable
|
10
|
+
|
11
|
+
def aop_disable
|
12
|
+
@aop_disabled = true
|
13
|
+
end
|
14
|
+
alias :disable :aop_disable
|
15
|
+
|
16
|
+
def aop_disabled?
|
17
|
+
@aop_disabled
|
18
|
+
end
|
19
|
+
alias :disabled? :aop_disabled?
|
20
|
+
|
6
21
|
def aop_advices
|
7
22
|
@aop_advices ||= []
|
8
23
|
end
|
@@ -9,17 +9,17 @@ module Aspector
|
|
9
9
|
@aop_creating_method or
|
10
10
|
@aop_instances.nil? or @aop_instances.empty?
|
11
11
|
|
12
|
-
|
13
|
-
return (block_given? and yield) if instance_variable_get(
|
12
|
+
aop_applied_flag = :"@aop_applied_#{method}"
|
13
|
+
return (block_given? and yield) if instance_variable_get(aop_applied_flag)
|
14
14
|
|
15
15
|
begin
|
16
|
-
instance_variable_set(
|
16
|
+
instance_variable_set(aop_applied_flag, true)
|
17
17
|
|
18
18
|
@aop_instances.apply_to_method(method.to_s)
|
19
19
|
|
20
20
|
yield if block_given?
|
21
21
|
ensure
|
22
|
-
instance_variable_set(
|
22
|
+
instance_variable_set(aop_applied_flag, nil)
|
23
23
|
end
|
24
24
|
end
|
25
25
|
|
@@ -29,20 +29,20 @@ module Aspector
|
|
29
29
|
|
30
30
|
return (block_given? and yield) if eigen_class.instance_variable_get(:@aop_creating_method)
|
31
31
|
|
32
|
-
|
33
|
-
return (block_given? and yield) if
|
32
|
+
aop_instances = eigen_class.instance_variable_get(:@aop_instances)
|
33
|
+
return (block_given? and yield) if aop_instances.nil? or aop_instances.empty?
|
34
34
|
|
35
|
-
|
36
|
-
return (block_given? and yield) if eigen_class.instance_variable_get(
|
35
|
+
aop_applied_flag = :"@aop_applied_#{method}"
|
36
|
+
return (block_given? and yield) if eigen_class.instance_variable_get(aop_applied_flag)
|
37
37
|
|
38
38
|
begin
|
39
|
-
eigen_class.instance_variable_set(
|
39
|
+
eigen_class.instance_variable_set(aop_applied_flag, true)
|
40
40
|
|
41
|
-
|
41
|
+
aop_instances.apply_to_method(method.to_s)
|
42
42
|
|
43
43
|
yield if block_given?
|
44
44
|
ensure
|
45
|
-
eigen_class.instance_variable_set(
|
45
|
+
eigen_class.instance_variable_set(aop_applied_flag, nil)
|
46
46
|
end
|
47
47
|
end
|
48
48
|
|
@@ -1,6 +1,8 @@
|
|
1
1
|
module Aspector
|
2
2
|
module ObjectExtension
|
3
3
|
|
4
|
+
private
|
5
|
+
|
4
6
|
def aspector *args, &block
|
5
7
|
options = args.last.is_a?(Hash) ? args.pop : {}
|
6
8
|
|
@@ -19,7 +21,13 @@ module Aspector
|
|
19
21
|
klass
|
20
22
|
end
|
21
23
|
|
24
|
+
def aop_return value = nil
|
25
|
+
throw :aop_return, value
|
26
|
+
end
|
27
|
+
alias :returns :aop_return
|
28
|
+
|
22
29
|
end
|
23
30
|
end
|
24
31
|
|
25
32
|
Object.send(:include, Aspector::ObjectExtension)
|
33
|
+
|
data/lib/aspector.rb
CHANGED
@@ -0,0 +1,65 @@
|
|
1
|
+
class A
|
2
|
+
def test input
|
3
|
+
input.upcase!
|
4
|
+
end
|
5
|
+
end
|
6
|
+
|
7
|
+
class B
|
8
|
+
def test input
|
9
|
+
input.upcase!
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
##############################
|
14
|
+
|
15
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
16
|
+
|
17
|
+
require 'aspector'
|
18
|
+
|
19
|
+
class AroundAspect < Aspector::Base
|
20
|
+
around :test do |proxy, *args, &block|
|
21
|
+
begin
|
22
|
+
proxy.call *args, &block
|
23
|
+
rescue => e
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
class RawAspect < Aspector::Base
|
29
|
+
target do
|
30
|
+
wrapped_method = instance_method(:test)
|
31
|
+
define_method :test do |*args, &block|
|
32
|
+
begin
|
33
|
+
wrapped_method.bind(self).call *args, &block
|
34
|
+
rescue => e
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
##############################
|
41
|
+
|
42
|
+
AroundAspect.apply(A)
|
43
|
+
RawAspect.apply(B)
|
44
|
+
|
45
|
+
a = A.new
|
46
|
+
b = B.new
|
47
|
+
|
48
|
+
require 'benchmark'
|
49
|
+
|
50
|
+
TIMES = 100000
|
51
|
+
Benchmark.bmbm do |x|
|
52
|
+
x.report "Around advice - good" do
|
53
|
+
TIMES.times { a.test 'good' }
|
54
|
+
end
|
55
|
+
x.report "Around advice - bad" do
|
56
|
+
TIMES.times { a.test nil }
|
57
|
+
end
|
58
|
+
x.report "Raw - good" do
|
59
|
+
TIMES.times { b.test 'good' }
|
60
|
+
end
|
61
|
+
x.report "Raw - bad" do
|
62
|
+
TIMES.times { b.test nil }
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
@@ -22,9 +22,9 @@ describe "Aspector for eigen class" do
|
|
22
22
|
result
|
23
23
|
end
|
24
24
|
|
25
|
-
around :test do
|
25
|
+
around :test do |proxy, &block|
|
26
26
|
value << "do_around_before"
|
27
|
-
result =
|
27
|
+
result = proxy.call &block
|
28
28
|
value << "do_around_after"
|
29
29
|
result
|
30
30
|
end
|
@@ -51,9 +51,9 @@ describe "Aspector for eigen class" do
|
|
51
51
|
result
|
52
52
|
end
|
53
53
|
|
54
|
-
around :test do
|
54
|
+
around :test do |proxy, &block|
|
55
55
|
value << "do_around_before"
|
56
|
-
result =
|
56
|
+
result = proxy.call &block
|
57
57
|
value << "do_around_after"
|
58
58
|
result
|
59
59
|
end
|
@@ -12,9 +12,9 @@ describe "Aspector" do
|
|
12
12
|
result
|
13
13
|
end
|
14
14
|
|
15
|
-
around :test do
|
15
|
+
around :test do |proxy, &block|
|
16
16
|
value << "do_around_before"
|
17
|
-
result =
|
17
|
+
result = proxy.call &block
|
18
18
|
value << "do_around_after"
|
19
19
|
result
|
20
20
|
end
|
@@ -39,9 +39,9 @@ describe "Aspector" do
|
|
39
39
|
result
|
40
40
|
end
|
41
41
|
|
42
|
-
around(:test) do
|
42
|
+
around(:test) do |proxy, &block|
|
43
43
|
value << "do_around_before(#{name})"
|
44
|
-
result =
|
44
|
+
result = proxy.call &block
|
45
45
|
value << "do_around_after(#{name})"
|
46
46
|
result
|
47
47
|
end
|
@@ -12,9 +12,9 @@ describe "Aspects combined" do
|
|
12
12
|
result
|
13
13
|
end
|
14
14
|
|
15
|
-
around :test do
|
15
|
+
around :test do |proxy, &block|
|
16
16
|
value << "do_around_before"
|
17
|
-
result =
|
17
|
+
result = proxy.call &block
|
18
18
|
value << "do_around_after"
|
19
19
|
result
|
20
20
|
end
|
@@ -28,9 +28,9 @@ describe "Aspects combined" do
|
|
28
28
|
result
|
29
29
|
end
|
30
30
|
|
31
|
-
around :test do
|
31
|
+
around :test do |proxy, &block|
|
32
32
|
value << "do_around_before2"
|
33
|
-
result =
|
33
|
+
result = proxy.call &block
|
34
34
|
value << "do_around_after2"
|
35
35
|
result
|
36
36
|
end
|
@@ -12,9 +12,9 @@ describe "Aspect execution order" do
|
|
12
12
|
result
|
13
13
|
end
|
14
14
|
|
15
|
-
around :test do
|
15
|
+
around :test do |proxy, &block|
|
16
16
|
value << "do_around_before"
|
17
|
-
result =
|
17
|
+
result = proxy.call &block
|
18
18
|
value << "do_around_after"
|
19
19
|
result
|
20
20
|
end
|
@@ -26,9 +26,9 @@ describe "Aspect execution order" do
|
|
26
26
|
result
|
27
27
|
end
|
28
28
|
|
29
|
-
around :test do
|
29
|
+
around :test do |proxy, &block|
|
30
30
|
value << "do_around_before2"
|
31
|
-
result =
|
31
|
+
result = proxy.call &block
|
32
32
|
value << "do_around_after2"
|
33
33
|
result
|
34
34
|
end
|
data/spec/unit/around_spec.rb
CHANGED
@@ -3,9 +3,9 @@ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
|
3
3
|
describe "Around advices" do
|
4
4
|
it "should work" do
|
5
5
|
klass = create_test_class do
|
6
|
-
def do_this &block
|
6
|
+
def do_this proxy, &block
|
7
7
|
value << "before"
|
8
|
-
result =
|
8
|
+
result = proxy.call &block
|
9
9
|
value << "after"
|
10
10
|
result
|
11
11
|
end
|
@@ -24,9 +24,9 @@ describe "Around advices" do
|
|
24
24
|
klass = create_test_class
|
25
25
|
|
26
26
|
aspector(klass) do
|
27
|
-
around :test do
|
27
|
+
around :test do |proxy, &block|
|
28
28
|
value << "before"
|
29
|
-
result =
|
29
|
+
result = proxy.call &block
|
30
30
|
value << "after"
|
31
31
|
result
|
32
32
|
end
|
@@ -39,9 +39,9 @@ describe "Around advices" do
|
|
39
39
|
|
40
40
|
it "method_name_arg" do
|
41
41
|
klass = create_test_class do
|
42
|
-
def do_this method, &block
|
42
|
+
def do_this method, proxy, &block
|
43
43
|
value << "before(#{method})"
|
44
|
-
result =
|
44
|
+
result = proxy.call &block
|
45
45
|
value << "after(#{method})"
|
46
46
|
result
|
47
47
|
end
|
metadata
CHANGED
@@ -1,134 +1,187 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: aspector
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 59
|
5
5
|
prerelease:
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 9
|
9
|
+
- 0
|
10
|
+
version: 0.9.0
|
6
11
|
platform: ruby
|
7
|
-
authors:
|
12
|
+
authors:
|
8
13
|
- Guoliang Cao
|
9
14
|
autorequire:
|
10
15
|
bindir: bin
|
11
16
|
cert_chain: []
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
requirement: &
|
17
|
+
|
18
|
+
date: 2012-03-08 00:00:00 Z
|
19
|
+
dependencies:
|
20
|
+
- !ruby/object:Gem::Dependency
|
21
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
17
22
|
none: false
|
18
|
-
requirements:
|
19
|
-
- -
|
20
|
-
- !ruby/object:Gem::Version
|
21
|
-
|
22
|
-
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
hash: 3
|
27
|
+
segments:
|
28
|
+
- 0
|
29
|
+
version: "0"
|
30
|
+
version_requirements: *id001
|
31
|
+
name: rspec
|
23
32
|
prerelease: false
|
24
|
-
|
25
|
-
- !ruby/object:Gem::Dependency
|
26
|
-
|
27
|
-
requirement: &2163247120 !ruby/object:Gem::Requirement
|
33
|
+
type: :development
|
34
|
+
- !ruby/object:Gem::Dependency
|
35
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
28
36
|
none: false
|
29
|
-
requirements:
|
37
|
+
requirements:
|
30
38
|
- - ~>
|
31
|
-
- !ruby/object:Gem::Version
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
hash: 7
|
41
|
+
segments:
|
42
|
+
- 1
|
43
|
+
- 6
|
44
|
+
- 4
|
32
45
|
version: 1.6.4
|
33
|
-
|
46
|
+
version_requirements: *id002
|
47
|
+
name: jeweler
|
34
48
|
prerelease: false
|
35
|
-
version_requirements: *2163247120
|
36
|
-
- !ruby/object:Gem::Dependency
|
37
|
-
name: ruby-prof
|
38
|
-
requirement: &2163246500 !ruby/object:Gem::Requirement
|
39
|
-
none: false
|
40
|
-
requirements:
|
41
|
-
- - ! '>='
|
42
|
-
- !ruby/object:Gem::Version
|
43
|
-
version: '0'
|
44
49
|
type: :development
|
50
|
+
- !ruby/object:Gem::Dependency
|
51
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
52
|
+
none: false
|
53
|
+
requirements:
|
54
|
+
- - ">="
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
hash: 3
|
57
|
+
segments:
|
58
|
+
- 0
|
59
|
+
version: "0"
|
60
|
+
version_requirements: *id003
|
61
|
+
name: ruby-prof
|
45
62
|
prerelease: false
|
46
|
-
|
47
|
-
- !ruby/object:Gem::Dependency
|
48
|
-
|
49
|
-
requirement: &2163245920 !ruby/object:Gem::Requirement
|
63
|
+
type: :development
|
64
|
+
- !ruby/object:Gem::Dependency
|
65
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
50
66
|
none: false
|
51
|
-
requirements:
|
67
|
+
requirements:
|
52
68
|
- - ~>
|
53
|
-
- !ruby/object:Gem::Version
|
69
|
+
- !ruby/object:Gem::Version
|
70
|
+
hash: 55
|
71
|
+
segments:
|
72
|
+
- 0
|
73
|
+
- 8
|
74
|
+
- 4
|
54
75
|
version: 0.8.4
|
55
|
-
|
76
|
+
version_requirements: *id004
|
77
|
+
name: guard
|
56
78
|
prerelease: false
|
57
|
-
|
58
|
-
- !ruby/object:Gem::Dependency
|
59
|
-
|
60
|
-
requirement: &2163245340 !ruby/object:Gem::Requirement
|
79
|
+
type: :development
|
80
|
+
- !ruby/object:Gem::Dependency
|
81
|
+
requirement: &id005 !ruby/object:Gem::Requirement
|
61
82
|
none: false
|
62
|
-
requirements:
|
83
|
+
requirements:
|
63
84
|
- - ~>
|
64
|
-
- !ruby/object:Gem::Version
|
85
|
+
- !ruby/object:Gem::Version
|
86
|
+
hash: 29
|
87
|
+
segments:
|
88
|
+
- 0
|
89
|
+
- 1
|
90
|
+
- 3
|
65
91
|
version: 0.1.3
|
66
|
-
|
92
|
+
version_requirements: *id005
|
93
|
+
name: guard-bundler
|
67
94
|
prerelease: false
|
68
|
-
|
69
|
-
- !ruby/object:Gem::Dependency
|
70
|
-
|
71
|
-
requirement: &2163244740 !ruby/object:Gem::Requirement
|
95
|
+
type: :development
|
96
|
+
- !ruby/object:Gem::Dependency
|
97
|
+
requirement: &id006 !ruby/object:Gem::Requirement
|
72
98
|
none: false
|
73
|
-
requirements:
|
99
|
+
requirements:
|
74
100
|
- - ~>
|
75
|
-
- !ruby/object:Gem::Version
|
101
|
+
- !ruby/object:Gem::Version
|
102
|
+
hash: 15
|
103
|
+
segments:
|
104
|
+
- 0
|
105
|
+
- 5
|
106
|
+
- 2
|
76
107
|
version: 0.5.2
|
77
|
-
|
108
|
+
version_requirements: *id006
|
109
|
+
name: guard-rspec
|
78
110
|
prerelease: false
|
79
|
-
|
80
|
-
- !ruby/object:Gem::Dependency
|
81
|
-
|
82
|
-
requirement: &2163244140 !ruby/object:Gem::Requirement
|
111
|
+
type: :development
|
112
|
+
- !ruby/object:Gem::Dependency
|
113
|
+
requirement: &id007 !ruby/object:Gem::Requirement
|
83
114
|
none: false
|
84
|
-
requirements:
|
115
|
+
requirements:
|
85
116
|
- - ~>
|
86
|
-
- !ruby/object:Gem::Version
|
117
|
+
- !ruby/object:Gem::Version
|
118
|
+
hash: 25
|
119
|
+
segments:
|
120
|
+
- 0
|
121
|
+
- 1
|
122
|
+
- 1
|
87
123
|
version: 0.1.1
|
88
|
-
|
124
|
+
version_requirements: *id007
|
125
|
+
name: guard-shell
|
89
126
|
prerelease: false
|
90
|
-
|
91
|
-
- !ruby/object:Gem::Dependency
|
92
|
-
|
93
|
-
requirement: &2163243540 !ruby/object:Gem::Requirement
|
127
|
+
type: :development
|
128
|
+
- !ruby/object:Gem::Dependency
|
129
|
+
requirement: &id008 !ruby/object:Gem::Requirement
|
94
130
|
none: false
|
95
|
-
requirements:
|
131
|
+
requirements:
|
96
132
|
- - ~>
|
97
|
-
- !ruby/object:Gem::Version
|
133
|
+
- !ruby/object:Gem::Version
|
134
|
+
hash: 97
|
135
|
+
segments:
|
136
|
+
- 0
|
137
|
+
- 4
|
138
|
+
- 3
|
139
|
+
- 1
|
98
140
|
version: 0.4.3.1
|
99
|
-
|
141
|
+
version_requirements: *id008
|
142
|
+
name: rb-fsevent
|
100
143
|
prerelease: false
|
101
|
-
|
102
|
-
- !ruby/object:Gem::Dependency
|
103
|
-
|
104
|
-
requirement: &2163242940 !ruby/object:Gem::Requirement
|
144
|
+
type: :development
|
145
|
+
- !ruby/object:Gem::Dependency
|
146
|
+
requirement: &id009 !ruby/object:Gem::Requirement
|
105
147
|
none: false
|
106
|
-
requirements:
|
148
|
+
requirements:
|
107
149
|
- - ~>
|
108
|
-
- !ruby/object:Gem::Version
|
150
|
+
- !ruby/object:Gem::Version
|
151
|
+
hash: 17
|
152
|
+
segments:
|
153
|
+
- 1
|
154
|
+
- 0
|
155
|
+
- 3
|
109
156
|
version: 1.0.3
|
110
|
-
|
157
|
+
version_requirements: *id009
|
158
|
+
name: growl
|
111
159
|
prerelease: false
|
112
|
-
version_requirements: *2163242940
|
113
|
-
- !ruby/object:Gem::Dependency
|
114
|
-
name: awesome_print
|
115
|
-
requirement: &2163242340 !ruby/object:Gem::Requirement
|
116
|
-
none: false
|
117
|
-
requirements:
|
118
|
-
- - ! '>='
|
119
|
-
- !ruby/object:Gem::Version
|
120
|
-
version: '0'
|
121
160
|
type: :development
|
161
|
+
- !ruby/object:Gem::Dependency
|
162
|
+
requirement: &id010 !ruby/object:Gem::Requirement
|
163
|
+
none: false
|
164
|
+
requirements:
|
165
|
+
- - ">="
|
166
|
+
- !ruby/object:Gem::Version
|
167
|
+
hash: 3
|
168
|
+
segments:
|
169
|
+
- 0
|
170
|
+
version: "0"
|
171
|
+
version_requirements: *id010
|
172
|
+
name: awesome_print
|
122
173
|
prerelease: false
|
123
|
-
|
124
|
-
description:
|
174
|
+
type: :development
|
175
|
+
description: ""
|
125
176
|
email: gcao99@gmail.com
|
126
177
|
executables: []
|
178
|
+
|
127
179
|
extensions: []
|
128
|
-
|
180
|
+
|
181
|
+
extra_rdoc_files:
|
129
182
|
- LICENSE.txt
|
130
183
|
- README.rdoc
|
131
|
-
files:
|
184
|
+
files:
|
132
185
|
- .document
|
133
186
|
- .irbrc
|
134
187
|
- .rspec
|
@@ -160,8 +213,8 @@ files:
|
|
160
213
|
- lib/aspector/method_matcher.rb
|
161
214
|
- lib/aspector/module_extension.rb
|
162
215
|
- lib/aspector/object_extension.rb
|
163
|
-
- lib/aspector/return_this.rb
|
164
216
|
- performance-tests/after_test.rb
|
217
|
+
- performance-tests/around_advice_benchmark.rb
|
165
218
|
- performance-tests/around_test.rb
|
166
219
|
- performance-tests/before_test.rb
|
167
220
|
- performance-tests/combined_test.rb
|
@@ -183,31 +236,37 @@ files:
|
|
183
236
|
- spec/unit/deferred_logic_spec.rb
|
184
237
|
- spec/unit/method_matcher_spec.rb
|
185
238
|
homepage: http://github.com/gcao/aspector
|
186
|
-
licenses:
|
239
|
+
licenses:
|
187
240
|
- MIT
|
188
241
|
post_install_message:
|
189
242
|
rdoc_options: []
|
190
|
-
|
243
|
+
|
244
|
+
require_paths:
|
191
245
|
- lib
|
192
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
246
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
193
247
|
none: false
|
194
|
-
requirements:
|
195
|
-
- -
|
196
|
-
- !ruby/object:Gem::Version
|
197
|
-
|
198
|
-
segments:
|
248
|
+
requirements:
|
249
|
+
- - ">="
|
250
|
+
- !ruby/object:Gem::Version
|
251
|
+
hash: 3
|
252
|
+
segments:
|
199
253
|
- 0
|
200
|
-
|
201
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
254
|
+
version: "0"
|
255
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
202
256
|
none: false
|
203
|
-
requirements:
|
204
|
-
- -
|
205
|
-
- !ruby/object:Gem::Version
|
206
|
-
|
257
|
+
requirements:
|
258
|
+
- - ">="
|
259
|
+
- !ruby/object:Gem::Version
|
260
|
+
hash: 3
|
261
|
+
segments:
|
262
|
+
- 0
|
263
|
+
version: "0"
|
207
264
|
requirements: []
|
265
|
+
|
208
266
|
rubyforge_project:
|
209
267
|
rubygems_version: 1.8.15
|
210
268
|
signing_key:
|
211
269
|
specification_version: 3
|
212
270
|
summary: Aspect Oriented Ruby Programming
|
213
271
|
test_files: []
|
272
|
+
|