aspector 0.9.1 → 0.10.0

Sign up to get free protection for your applications and to get access to all the features.
data/.rvmrc CHANGED
@@ -1,8 +1,8 @@
1
1
  rvm_gemset_create_on_use_flag=1
2
2
 
3
- if [ "$RUBY_VERSION" == "1.9" ]; then
4
- rvm use 1.9.2@aspector
5
- else
3
+ if [ "$RUBY_VERSION" == "1.8" ]; then
6
4
  rvm use 1.8.7@aspector
5
+ else
6
+ rvm use 1.9.3@aspector
7
7
  fi
8
8
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.9.1
1
+ 0.10.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.9.1"
8
+ s.version = "0.10.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-03-13"
12
+ s.date = "2012-03-19"
13
13
  s.description = ""
14
14
  s.email = "gcao99@gmail.com"
15
15
  s.extra_rdoc_files = [
@@ -74,7 +74,7 @@ Gem::Specification.new do |s|
74
74
  s.homepage = "http://github.com/gcao/aspector"
75
75
  s.licenses = ["MIT"]
76
76
  s.require_paths = ["lib"]
77
- s.rubygems_version = "1.8.15"
77
+ s.rubygems_version = "1.8.18"
78
78
  s.summary = "Aspect Oriented Ruby Programming"
79
79
 
80
80
  if s.respond_to? :specification_version then
@@ -46,15 +46,12 @@ require 'aspector'
46
46
  class CacheAspect < Aspector::Base
47
47
  default :ttl => 60
48
48
 
49
- def after_initialize
50
- aspect = self
51
- around options[:method], :method_name_arg => true do |method, proxy, &block|
52
- key = method
53
- ttl = aspect.options[:ttl]
54
-
55
- SimpleCache.cache key, ttl do
56
- proxy.call &block
57
- end
49
+ around options[:method], :aspect_arg => true, :method_arg => true do |aspect, method, proxy, &block|
50
+ key = method
51
+ ttl = aspect.options[:ttl]
52
+
53
+ SimpleCache.cache key, ttl do
54
+ proxy.call &block
58
55
  end
59
56
  end
60
57
 
@@ -16,7 +16,7 @@ class LoggingAspect < Aspector::Base
16
16
 
17
17
  ALL_METHODS = /.*/
18
18
 
19
- around ALL_METHODS, :except => :class, :method_name_arg => true do |method, proxy, *args, &block|
19
+ around ALL_METHODS, :except => :class, :method_arg => true do |method, proxy, *args, &block|
20
20
  class_method = "#{self.class}.#{method}"
21
21
  puts "Entering #{class_method}: #{args.join(',')}"
22
22
  result = proxy.call *args, &block
data/lib/aspector/base.rb CHANGED
@@ -30,6 +30,8 @@ module Aspector
30
30
  class << self
31
31
  def aop_disabled?; end
32
32
  end
33
+
34
+ aop_disabled?
33
35
  end
34
36
  alias enable aop_enable
35
37
 
@@ -37,6 +39,8 @@ module Aspector
37
39
  class << self
38
40
  def aop_disabled?; true; end
39
41
  end
42
+
43
+ aop_disabled?
40
44
  end
41
45
  alias disable aop_disable
42
46
 
@@ -44,6 +48,8 @@ module Aspector
44
48
  class << self
45
49
  remove_method :aop_disabled?
46
50
  end
51
+
52
+ aop_disabled?
47
53
  end
48
54
  alias reset_disabled :aop_reset_disabled
49
55
 
@@ -51,21 +57,11 @@ module Aspector
51
57
  end
52
58
 
53
59
  def disabled?
54
- aop_disabled
60
+ aop_disabled?
55
61
  end
56
62
 
57
63
  def aop_advices
58
- shared_advices = self.class.aop_advices
59
-
60
- if shared_advices and shared_advices.size > 0
61
- if @aop_advices
62
- @aop_advices + shared_advices
63
- else
64
- shared_advices
65
- end
66
- else
67
- @aop_advices or []
68
- end
64
+ self.class.aop_advices
69
65
  end
70
66
  alias :advices :aop_advices
71
67
 
@@ -152,30 +148,6 @@ module Aspector
152
148
  def after_apply_to_method method, advices
153
149
  end
154
150
 
155
- def aop_before *methods, &block
156
- @aop_advices ||= []
157
- @aop_advices << self.class.send(:aop_create_advice, Aspector::AdviceMetadata::BEFORE, self, methods, &block)
158
- end
159
- alias :before :aop_before
160
-
161
- def aop_before_filter *methods, &block
162
- @aop_advices ||= []
163
- @aop_advices << self.class.send(:aop_create_advice, Aspector::AdviceMetadata::BEFORE_FILTER, self, methods, &block)
164
- end
165
- alias :before_filter :aop_before_filter
166
-
167
- def aop_after *methods, &block
168
- @aop_advices ||= []
169
- @aop_advices << self.class.send(:aop_create_advice, Aspector::AdviceMetadata::AFTER, self, methods, &block)
170
- end
171
- alias :after :aop_after
172
-
173
- def aop_around *methods, &block
174
- @aop_advices ||= []
175
- @aop_advices << self.class.send(:aop_create_advice, Aspector::AdviceMetadata::AROUND, self, methods, &block)
176
- end
177
- alias :around :aop_around
178
-
179
151
  private
180
152
 
181
153
  def aop_deferred_logic_results logic
@@ -294,12 +266,11 @@ module Aspector
294
266
  <% end %>
295
267
 
296
268
  # Before advices
297
- <% before_advices.each do |advice|
298
- if advice.options[:method_name_arg] %>
299
- result = <%= advice.with_method %> '<%= method %>', *args
300
- <% else %>
301
- result = <%= advice.with_method %> *args
302
- <% end %>
269
+ <% before_advices.each do |advice| %>
270
+ result = <%= advice.with_method %> <%
271
+ if advice.options[:aspect_arg] %>aspect, <% end %><%
272
+ if advice.options[:method_arg] %>'<%= method %>', <% end
273
+ %>*args
303
274
 
304
275
  <% if advice.options[:skip_if_false] %>
305
276
  return unless result
@@ -309,13 +280,11 @@ module Aspector
309
280
 
310
281
  <% if around_advice %>
311
282
  # Around advice
312
- <% if around_advice.options[:method_name_arg] %>
313
- result = <%= around_advice.with_method %> '<%= method %>', wrapped_method.bind(self), *args, &block
314
- <% else %>
315
- result = <%= around_advice.with_method %> wrapped_method.bind(self), *args, &block
316
- <% end
317
- else
318
- %>
283
+ result = <%= around_advice.with_method %> <%
284
+ if around_advice.options[:aspect_arg] %>aspect, <% end %><%
285
+ if around_advice.options[:method_arg] %>'<%= method %>', <% end
286
+ %>wrapped_method.bind(self), *args, &block
287
+ <% else %>
319
288
  # Invoke original method
320
289
  result = orig_method.bind(self).call *args, &block
321
290
  <% end %>
@@ -323,18 +292,18 @@ module Aspector
323
292
  # After advices
324
293
  <% unless after_advices.empty?
325
294
  after_advices.each do |advice|
326
- if advice.options[:method_name_arg]
327
- if advice.options[:result_arg]
328
- %>
329
- result = <%= advice.with_method %> '<%= method %>', result, *args
330
- <% else %>
331
- <%= advice.with_method %> '<%= method %>', *args
332
- <% end
333
- elsif advice.options[:result_arg]
295
+ if advice.options[:result_arg]
334
296
  %>
335
- result = <%= advice.with_method %> result, *args
297
+ result = <%= advice.with_method %> <%
298
+ if advice.options[:aspect_arg] %>aspect, <% end %><%
299
+ if advice.options[:method_arg] %>'<%= method %>', <% end %><%
300
+ if advice.options[:result_arg] %>result, <% end
301
+ %>*args
336
302
  <% else %>
337
- <%= advice.with_method %> *args
303
+ <%= advice.with_method %> <%
304
+ if advice.options[:aspect_arg] %>aspect, <% end %><%
305
+ if advice.options[:method_arg] %>'<%= method %>', <% end
306
+ %>*args
338
307
  <% end
339
308
  end
340
309
  %>
@@ -4,15 +4,19 @@ module Aspector
4
4
  ::Aspector::Base.extend(self)
5
5
 
6
6
  def aop_enable
7
- def aop_disabled?
7
+ send :define_method, :aop_disabled? do
8
8
  end
9
+
10
+ nil
9
11
  end
10
12
  alias :enable :aop_enable
11
13
 
12
14
  def aop_disable
13
- def aop_disabled?
15
+ send :define_method, :aop_disabled? do
14
16
  true
15
17
  end
18
+
19
+ nil
16
20
  end
17
21
  alias :disable :aop_disable
18
22
 
@@ -25,34 +25,6 @@ describe "Aspector" do
25
25
  obj.value.should == %w"do_before do_around_before test do_around_after do_after"
26
26
  end
27
27
 
28
- it "advices defined in after_initialization" do
29
- klass = create_test_class
30
-
31
- aspector(klass) do
32
- def after_initialize
33
- name = 'this'
34
-
35
- before(:test) { value << "do_before(#{name})" }
36
-
37
- after(:test) do |result|
38
- value << "do_after(#{name})"
39
- result
40
- end
41
-
42
- around(:test) do |proxy, &block|
43
- value << "do_around_before(#{name})"
44
- result = proxy.call &block
45
- value << "do_around_after(#{name})"
46
- result
47
- end
48
- end
49
- end
50
-
51
- obj = klass.new
52
- obj.test
53
- obj.value.should == %w"do_before(this) do_around_before(this) test do_around_after(this) do_after(this)"
54
- end
55
-
56
28
  it "multiple aspects should work together" do
57
29
  klass = create_test_class
58
30
  aspector(klass) do
@@ -18,7 +18,7 @@ describe "After advices" do
18
18
  obj.value.should == %w"test do_this"
19
19
  end
20
20
 
21
- it "method_name_arg" do
21
+ it "method_arg" do
22
22
  klass = create_test_class do
23
23
  def do_this method, result
24
24
  value << "do_this(#{method})"
@@ -27,7 +27,7 @@ describe "After advices" do
27
27
  end
28
28
 
29
29
  aspector(klass) do
30
- after :test, :do_this, :method_name_arg => true
30
+ after :test, :do_this, :method_arg => true
31
31
  end
32
32
 
33
33
  obj = klass.new
@@ -37,7 +37,7 @@ describe "Around advices" do
37
37
  obj.value.should == %w"before test after"
38
38
  end
39
39
 
40
- it "method_name_arg" do
40
+ it "method_arg" do
41
41
  klass = create_test_class do
42
42
  def do_this method, proxy, &block
43
43
  value << "before(#{method})"
@@ -48,7 +48,7 @@ describe "Around advices" do
48
48
  end
49
49
 
50
50
  aspector(klass) do
51
- around :test, :do_this, :method_name_arg => true
51
+ around :test, :do_this, :method_arg => true
52
52
  end
53
53
 
54
54
  obj = klass.new
@@ -53,10 +53,10 @@ describe "Before advices" do
53
53
  obj.value.should == %w"do_this test"
54
54
  end
55
55
 
56
- it "method_name_arg" do
56
+ it "method_arg" do
57
57
  klass = Class.new do
58
58
  aspector do
59
- before :test, :do_this, :method_name_arg => true
59
+ before :test, :do_this, :method_arg => true
60
60
  end
61
61
 
62
62
  def value
metadata CHANGED
@@ -1,201 +1,200 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: aspector
3
- version: !ruby/object:Gem::Version
4
- hash: 57
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.10.0
5
5
  prerelease:
6
- segments:
7
- - 0
8
- - 9
9
- - 1
10
- version: 0.9.1
11
6
  platform: ruby
12
- authors:
7
+ authors:
13
8
  - Guoliang Cao
14
9
  autorequire:
15
10
  bindir: bin
16
11
  cert_chain: []
17
-
18
- date: 2012-03-13 00:00:00 Z
19
- dependencies:
20
- - !ruby/object:Gem::Dependency
21
- requirement: &id001 !ruby/object:Gem::Requirement
22
- none: false
23
- requirements:
24
- - - ">="
25
- - !ruby/object:Gem::Version
26
- hash: 3
27
- segments:
28
- - 0
29
- version: "0"
30
- version_requirements: *id001
12
+ date: 2012-03-19 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
31
15
  name: rspec
32
- prerelease: false
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
33
22
  type: :development
34
- - !ruby/object:Gem::Dependency
35
- requirement: &id002 !ruby/object:Gem::Requirement
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
36
25
  none: false
37
- requirements:
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: jeweler
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
38
35
  - - ~>
39
- - !ruby/object:Gem::Version
40
- hash: 7
41
- segments:
42
- - 1
43
- - 6
44
- - 4
36
+ - !ruby/object:Gem::Version
45
37
  version: 1.6.4
46
- version_requirements: *id002
47
- name: jeweler
48
- prerelease: false
49
38
  type: :development
50
- - !ruby/object:Gem::Dependency
51
- requirement: &id003 !ruby/object:Gem::Requirement
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
52
41
  none: false
53
- requirements:
54
- - - ">="
55
- - !ruby/object:Gem::Version
56
- hash: 3
57
- segments:
58
- - 0
59
- version: "0"
60
- version_requirements: *id003
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ version: 1.6.4
46
+ - !ruby/object:Gem::Dependency
61
47
  name: ruby-prof
62
- prerelease: false
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
63
54
  type: :development
64
- - !ruby/object:Gem::Dependency
65
- requirement: &id004 !ruby/object:Gem::Requirement
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ - !ruby/object:Gem::Dependency
63
+ name: guard
64
+ requirement: !ruby/object:Gem::Requirement
66
65
  none: false
67
- requirements:
66
+ requirements:
68
67
  - - ~>
69
- - !ruby/object:Gem::Version
70
- hash: 55
71
- segments:
72
- - 0
73
- - 8
74
- - 4
68
+ - !ruby/object:Gem::Version
75
69
  version: 0.8.4
76
- version_requirements: *id004
77
- name: guard
78
- prerelease: false
79
70
  type: :development
80
- - !ruby/object:Gem::Dependency
81
- requirement: &id005 !ruby/object:Gem::Requirement
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
82
73
  none: false
83
- requirements:
74
+ requirements:
84
75
  - - ~>
85
- - !ruby/object:Gem::Version
86
- hash: 29
87
- segments:
88
- - 0
89
- - 1
90
- - 3
91
- version: 0.1.3
92
- version_requirements: *id005
76
+ - !ruby/object:Gem::Version
77
+ version: 0.8.4
78
+ - !ruby/object:Gem::Dependency
93
79
  name: guard-bundler
94
- prerelease: false
80
+ requirement: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ~>
84
+ - !ruby/object:Gem::Version
85
+ version: 0.1.3
95
86
  type: :development
96
- - !ruby/object:Gem::Dependency
97
- requirement: &id006 !ruby/object:Gem::Requirement
87
+ prerelease: false
88
+ version_requirements: !ruby/object:Gem::Requirement
98
89
  none: false
99
- requirements:
90
+ requirements:
100
91
  - - ~>
101
- - !ruby/object:Gem::Version
102
- hash: 15
103
- segments:
104
- - 0
105
- - 5
106
- - 2
107
- version: 0.5.2
108
- version_requirements: *id006
92
+ - !ruby/object:Gem::Version
93
+ version: 0.1.3
94
+ - !ruby/object:Gem::Dependency
109
95
  name: guard-rspec
110
- prerelease: false
96
+ requirement: !ruby/object:Gem::Requirement
97
+ none: false
98
+ requirements:
99
+ - - ~>
100
+ - !ruby/object:Gem::Version
101
+ version: 0.5.2
111
102
  type: :development
112
- - !ruby/object:Gem::Dependency
113
- requirement: &id007 !ruby/object:Gem::Requirement
103
+ prerelease: false
104
+ version_requirements: !ruby/object:Gem::Requirement
114
105
  none: false
115
- requirements:
106
+ requirements:
116
107
  - - ~>
117
- - !ruby/object:Gem::Version
118
- hash: 25
119
- segments:
120
- - 0
121
- - 1
122
- - 1
123
- version: 0.1.1
124
- version_requirements: *id007
108
+ - !ruby/object:Gem::Version
109
+ version: 0.5.2
110
+ - !ruby/object:Gem::Dependency
125
111
  name: guard-shell
126
- prerelease: false
112
+ requirement: !ruby/object:Gem::Requirement
113
+ none: false
114
+ requirements:
115
+ - - ~>
116
+ - !ruby/object:Gem::Version
117
+ version: 0.1.1
127
118
  type: :development
128
- - !ruby/object:Gem::Dependency
129
- requirement: &id008 !ruby/object:Gem::Requirement
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
130
121
  none: false
131
- requirements:
122
+ requirements:
132
123
  - - ~>
133
- - !ruby/object:Gem::Version
134
- hash: 97
135
- segments:
136
- - 0
137
- - 4
138
- - 3
139
- - 1
140
- version: 0.4.3.1
141
- version_requirements: *id008
124
+ - !ruby/object:Gem::Version
125
+ version: 0.1.1
126
+ - !ruby/object:Gem::Dependency
142
127
  name: rb-fsevent
143
- prerelease: false
128
+ requirement: !ruby/object:Gem::Requirement
129
+ none: false
130
+ requirements:
131
+ - - ~>
132
+ - !ruby/object:Gem::Version
133
+ version: 0.4.3.1
144
134
  type: :development
145
- - !ruby/object:Gem::Dependency
146
- requirement: &id009 !ruby/object:Gem::Requirement
135
+ prerelease: false
136
+ version_requirements: !ruby/object:Gem::Requirement
147
137
  none: false
148
- requirements:
138
+ requirements:
149
139
  - - ~>
150
- - !ruby/object:Gem::Version
151
- hash: 17
152
- segments:
153
- - 1
154
- - 0
155
- - 3
156
- version: 1.0.3
157
- version_requirements: *id009
140
+ - !ruby/object:Gem::Version
141
+ version: 0.4.3.1
142
+ - !ruby/object:Gem::Dependency
158
143
  name: growl
159
- prerelease: false
144
+ requirement: !ruby/object:Gem::Requirement
145
+ none: false
146
+ requirements:
147
+ - - ~>
148
+ - !ruby/object:Gem::Version
149
+ version: 1.0.3
160
150
  type: :development
161
- - !ruby/object:Gem::Dependency
162
- requirement: &id010 !ruby/object:Gem::Requirement
151
+ prerelease: false
152
+ version_requirements: !ruby/object:Gem::Requirement
163
153
  none: false
164
- requirements:
165
- - - ">="
166
- - !ruby/object:Gem::Version
167
- hash: 3
168
- segments:
169
- - 0
170
- version: "0"
171
- version_requirements: *id010
154
+ requirements:
155
+ - - ~>
156
+ - !ruby/object:Gem::Version
157
+ version: 1.0.3
158
+ - !ruby/object:Gem::Dependency
172
159
  name: awesome_print
173
- prerelease: false
160
+ requirement: !ruby/object:Gem::Requirement
161
+ none: false
162
+ requirements:
163
+ - - ! '>='
164
+ - !ruby/object:Gem::Version
165
+ version: '0'
174
166
  type: :development
175
- - !ruby/object:Gem::Dependency
176
- requirement: &id011 !ruby/object:Gem::Requirement
167
+ prerelease: false
168
+ version_requirements: !ruby/object:Gem::Requirement
177
169
  none: false
178
- requirements:
179
- - - ">="
180
- - !ruby/object:Gem::Version
181
- hash: 3
182
- segments:
183
- - 0
184
- version: "0"
185
- version_requirements: *id011
170
+ requirements:
171
+ - - ! '>='
172
+ - !ruby/object:Gem::Version
173
+ version: '0'
174
+ - !ruby/object:Gem::Dependency
186
175
  name: pry
187
- prerelease: false
176
+ requirement: !ruby/object:Gem::Requirement
177
+ none: false
178
+ requirements:
179
+ - - ! '>='
180
+ - !ruby/object:Gem::Version
181
+ version: '0'
188
182
  type: :development
189
- description: ""
183
+ prerelease: false
184
+ version_requirements: !ruby/object:Gem::Requirement
185
+ none: false
186
+ requirements:
187
+ - - ! '>='
188
+ - !ruby/object:Gem::Version
189
+ version: '0'
190
+ description: ''
190
191
  email: gcao99@gmail.com
191
192
  executables: []
192
-
193
193
  extensions: []
194
-
195
- extra_rdoc_files:
194
+ extra_rdoc_files:
196
195
  - LICENSE.txt
197
196
  - README.rdoc
198
- files:
197
+ files:
199
198
  - .document
200
199
  - .irbrc
201
200
  - .rspec
@@ -250,37 +249,31 @@ files:
250
249
  - spec/unit/deferred_logic_spec.rb
251
250
  - spec/unit/method_matcher_spec.rb
252
251
  homepage: http://github.com/gcao/aspector
253
- licenses:
252
+ licenses:
254
253
  - MIT
255
254
  post_install_message:
256
255
  rdoc_options: []
257
-
258
- require_paths:
256
+ require_paths:
259
257
  - lib
260
- required_ruby_version: !ruby/object:Gem::Requirement
258
+ required_ruby_version: !ruby/object:Gem::Requirement
261
259
  none: false
262
- requirements:
263
- - - ">="
264
- - !ruby/object:Gem::Version
265
- hash: 3
266
- segments:
260
+ requirements:
261
+ - - ! '>='
262
+ - !ruby/object:Gem::Version
263
+ version: '0'
264
+ segments:
267
265
  - 0
268
- version: "0"
269
- required_rubygems_version: !ruby/object:Gem::Requirement
266
+ hash: -2602659987837807092
267
+ required_rubygems_version: !ruby/object:Gem::Requirement
270
268
  none: false
271
- requirements:
272
- - - ">="
273
- - !ruby/object:Gem::Version
274
- hash: 3
275
- segments:
276
- - 0
277
- version: "0"
269
+ requirements:
270
+ - - ! '>='
271
+ - !ruby/object:Gem::Version
272
+ version: '0'
278
273
  requirements: []
279
-
280
274
  rubyforge_project:
281
- rubygems_version: 1.8.15
275
+ rubygems_version: 1.8.18
282
276
  signing_key:
283
277
  specification_version: 3
284
278
  summary: Aspect Oriented Ruby Programming
285
279
  test_files: []
286
-