aspector 0.10.0 → 0.10.1

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.10.0
1
+ 0.10.1
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.10.0"
8
+ s.version = "0.10.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 = "2012-03-19"
12
+ s.date = "2012-03-20"
13
13
  s.description = ""
14
14
  s.email = "gcao99@gmail.com"
15
15
  s.extra_rdoc_files = [
@@ -35,6 +35,7 @@ Gem::Specification.new do |s|
35
35
  "examples/aspector_example.rb",
36
36
  "examples/cache_aspect.rb",
37
37
  "examples/exception_handler.rb",
38
+ "examples/implicit_method_option_test.rb",
38
39
  "examples/logging_aspect.rb",
39
40
  "examples/retry_aspect.rb",
40
41
  "lib/aspector.rb",
@@ -0,0 +1,31 @@
1
+ class A
2
+ def test
3
+ puts 'test'
4
+ end
5
+ end
6
+
7
+ ##############################
8
+
9
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
10
+
11
+ require 'aspector'
12
+
13
+ class ImplicitMethodOptionTest < Aspector::Base
14
+ # Apply advice to options[:method] and options[:methods] if no target method is given
15
+ # before options[:method], options[:methods] do
16
+ before do
17
+ puts 'before'
18
+ end
19
+ end
20
+
21
+ # ImplicitMethodOptionTest.apply A, :method => 'test'
22
+ ImplicitMethodOptionTest.apply "A#test"
23
+
24
+ ##############################
25
+
26
+ A.new.test
27
+
28
+ # Expected output:
29
+ # before
30
+ # test
31
+
data/lib/aspector/base.rb CHANGED
@@ -155,7 +155,7 @@ module Aspector
155
155
  end
156
156
 
157
157
  def aop_get_context
158
- return @aop_target if @aop_target.is_a?(Module) and not @aop_options[:eigen_class]
158
+ return @aop_target if @aop_target.is_a?(Module) and not @aop_options[:class_methods]
159
159
 
160
160
  class << @aop_target
161
161
  self
@@ -189,7 +189,7 @@ module Aspector
189
189
  end
190
190
 
191
191
  def aop_add_method_hooks
192
- if @aop_options[:eigen_class]
192
+ if @aop_options[:class_methods]
193
193
  return unless @aop_target.is_a?(Module)
194
194
 
195
195
  eigen_class = class << @aop_target; self; end
@@ -31,6 +31,19 @@ module Aspector
31
31
  alias :default_options :aop_default_options
32
32
 
33
33
  def aop_apply target, options = {}
34
+ # Handle 'Klass#method' and 'Klass.method' shortcut
35
+ if target.is_a? String
36
+ if target.index('.')
37
+ target, method = target.split('.')
38
+ target = Object.const_get target
39
+ options.merge! :method => method, :class_methods => true
40
+ else
41
+ target, method = target.split('#')
42
+ target = Object.const_get target
43
+ options.merge! :method => method
44
+ end
45
+ end
46
+
34
47
  aspect_instance = new(target, options)
35
48
  aspect_instance.send :aop_apply
36
49
  aspect_instance
@@ -100,6 +113,8 @@ module Aspector
100
113
 
101
114
  with_method = methods.pop unless block_given?
102
115
 
116
+ methods << aop_options[:method] << aop_options[:methods] if methods.empty?
117
+
103
118
  Aspector::Advice.new(self,
104
119
  meta_data.advice_type,
105
120
  Aspector::MethodMatcher.new(*methods),
@@ -14,7 +14,7 @@ describe "Aspector for eigen class" do
14
14
  end
15
15
  end
16
16
 
17
- aspector(klass, :eigen_class => true) do
17
+ aspector(klass, :class_methods => true) do
18
18
  before :test do value << "do_before" end
19
19
 
20
20
  after :test do |result|
@@ -43,7 +43,7 @@ describe "Aspector for eigen class" do
43
43
  end
44
44
  end
45
45
 
46
- aspector(klass, :eigen_class => true) do
46
+ aspector(klass, :class_methods => true) do
47
47
  before :test do value << "do_before" end
48
48
 
49
49
  after :test do |result|
@@ -77,5 +77,57 @@ describe "Before advices" do
77
77
  obj.value.should == %w"do_this(test) test"
78
78
  end
79
79
 
80
+ it "implicit method option" do
81
+ ImplicitMethodOptionTest = create_test_class do
82
+ def do_this
83
+ value << "do_this"
84
+ end
85
+ end
86
+
87
+ aspector "ImplicitMethodOptionTest#test" do
88
+ before :do_this
89
+ end
90
+
91
+ o = ImplicitMethodOptionTest.new
92
+ o.test
93
+ o.value.should == %w"do_this test"
94
+ end
95
+
96
+ it "implicit methods option" do
97
+ klass = create_test_class do
98
+ def do_this
99
+ value << "do_this"
100
+ end
101
+ end
102
+
103
+ aspector klass, :methods => [:test] do
104
+ before :do_this
105
+ end
106
+
107
+ o = ImplicitMethodOptionTest.new
108
+ o.test
109
+ o.value.should == %w"do_this test"
110
+ end
111
+
112
+ it "klass.method shortcut" do
113
+ module KlassMethodTest
114
+ def self.value
115
+ @value ||= []
116
+ end
117
+
118
+ def self.test
119
+ value << "test"
120
+ end
121
+ end
122
+
123
+ aspector "KlassMethodTest.test" do
124
+ before do
125
+ value << "before"
126
+ end
127
+ end
128
+
129
+ KlassMethodTest.test.should == %w"before test"
130
+ end
131
+
80
132
  end
81
133
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: aspector
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.10.0
4
+ version: 0.10.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-03-19 00:00:00.000000000 Z
12
+ date: 2012-03-20 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec
@@ -213,6 +213,7 @@ files:
213
213
  - examples/aspector_example.rb
214
214
  - examples/cache_aspect.rb
215
215
  - examples/exception_handler.rb
216
+ - examples/implicit_method_option_test.rb
216
217
  - examples/logging_aspect.rb
217
218
  - examples/retry_aspect.rb
218
219
  - lib/aspector.rb
@@ -263,7 +264,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
263
264
  version: '0'
264
265
  segments:
265
266
  - 0
266
- hash: -2602659987837807092
267
+ hash: 3014402332352836990
267
268
  required_rubygems_version: !ruby/object:Gem::Requirement
268
269
  none: false
269
270
  requirements: