aspector 0.12.1 → 0.12.2
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/aspector.gemspec +2 -2
- data/lib/aspector/base_class_methods.rb +11 -5
- data/spec/unit/base_spec.rb +19 -0
- data/spec/unit/special_chars_spec.rb +69 -30
- metadata +3 -3
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.12.
|
1
|
+
0.12.2
|
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.12.
|
8
|
+
s.version = "0.12.2"
|
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-07-
|
12
|
+
s.date = "2012-07-03"
|
13
13
|
s.description = ""
|
14
14
|
s.email = "gcao99@gmail.com"
|
15
15
|
s.extra_rdoc_files = [
|
@@ -37,12 +37,18 @@ module Aspector
|
|
37
37
|
end
|
38
38
|
alias default_options aop_default_options
|
39
39
|
|
40
|
-
def aop_apply target,
|
41
|
-
|
40
|
+
def aop_apply target, *rest
|
41
|
+
options = rest.last.is_a?(Hash) ? rest.pop : {}
|
42
|
+
|
43
|
+
targets = rest.unshift target
|
44
|
+
result = targets.map do |target|
|
45
|
+
aop_logger.log Logger::APPLY, target, options.inspect
|
46
|
+
aspect_instance = new(target, options)
|
47
|
+
aspect_instance.send :aop_apply
|
48
|
+
aspect_instance
|
49
|
+
end
|
42
50
|
|
43
|
-
|
44
|
-
aspect_instance.send :aop_apply
|
45
|
-
aspect_instance
|
51
|
+
result.size == 1 ? result.first : result
|
46
52
|
end
|
47
53
|
alias apply aop_apply
|
48
54
|
|
data/spec/unit/base_spec.rb
CHANGED
@@ -39,6 +39,25 @@ describe "Aspector::Base" do
|
|
39
39
|
obj.value.should == %w"do_before test"
|
40
40
|
end
|
41
41
|
|
42
|
+
it "#apply to multiple targets at once" do
|
43
|
+
klass = create_test_class
|
44
|
+
klass2 = create_test_class
|
45
|
+
|
46
|
+
aspect = Aspector do
|
47
|
+
before :test do value << "do_before" end
|
48
|
+
end
|
49
|
+
|
50
|
+
aspect.apply(klass, klass2)
|
51
|
+
|
52
|
+
obj = klass.new
|
53
|
+
obj.test
|
54
|
+
obj.value.should == %w"do_before test"
|
55
|
+
|
56
|
+
obj2 = klass2.new
|
57
|
+
obj2.test
|
58
|
+
obj2.value.should == %w"do_before test"
|
59
|
+
end
|
60
|
+
|
42
61
|
it "use #target to add method to target class/module" do
|
43
62
|
klass = create_test_class
|
44
63
|
|
@@ -1,6 +1,6 @@
|
|
1
1
|
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
2
2
|
|
3
|
-
describe "
|
3
|
+
describe "special chars in method names" do
|
4
4
|
['?', '!', '='].each do |char|
|
5
5
|
it "should work with methods whose name contains #{char}" do
|
6
6
|
klass = Class.new do
|
@@ -16,11 +16,9 @@ describe "Special chars in method names" do
|
|
16
16
|
value << "do_this"
|
17
17
|
end
|
18
18
|
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
end
|
23
|
-
CODE
|
19
|
+
define_method "test#{char}" do |*args|
|
20
|
+
value << "test"
|
21
|
+
end
|
24
22
|
end
|
25
23
|
|
26
24
|
obj = klass.new
|
@@ -29,30 +27,6 @@ describe "Special chars in method names" do
|
|
29
27
|
end
|
30
28
|
end
|
31
29
|
|
32
|
-
it "should work with []" do
|
33
|
-
klass = Class.new do
|
34
|
-
aspector do
|
35
|
-
before "[]", :do_this
|
36
|
-
end
|
37
|
-
|
38
|
-
def value
|
39
|
-
@value ||= []
|
40
|
-
end
|
41
|
-
|
42
|
-
def do_this *args
|
43
|
-
value << "do_this"
|
44
|
-
end
|
45
|
-
|
46
|
-
def [] *args
|
47
|
-
value << "test"
|
48
|
-
end
|
49
|
-
end
|
50
|
-
|
51
|
-
obj = klass.new
|
52
|
-
obj[1]
|
53
|
-
obj.value.should == %w"do_this test"
|
54
|
-
end
|
55
|
-
|
56
30
|
['+', '-', '*', '/', '~', '|', '%', '&', '^', '<', '>', '[]', '[]='].each do |meth|
|
57
31
|
it "should work with #{meth}" do
|
58
32
|
klass = Class.new do
|
@@ -81,3 +55,68 @@ describe "Special chars in method names" do
|
|
81
55
|
|
82
56
|
end
|
83
57
|
|
58
|
+
describe "special chars in class method names" do
|
59
|
+
['?', '!', '='].each do |char|
|
60
|
+
it "should work with methods whose name contains #{char}" do
|
61
|
+
Object.send :define_method, :meth_with_special_char do
|
62
|
+
"test#{char}"
|
63
|
+
end
|
64
|
+
|
65
|
+
klass = Class.new do
|
66
|
+
aspector :class_methods => true do
|
67
|
+
before meth_with_special_char, :do_this
|
68
|
+
end
|
69
|
+
|
70
|
+
class << self
|
71
|
+
def value
|
72
|
+
@value ||= []
|
73
|
+
end
|
74
|
+
|
75
|
+
def do_this *args
|
76
|
+
value << "do_this"
|
77
|
+
end
|
78
|
+
|
79
|
+
define_method meth_with_special_char do |*args|
|
80
|
+
value << "test"
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
klass.send meth_with_special_char, 1
|
86
|
+
klass.value.should == %w"do_this test"
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
['+', '-', '*', '/', '~', '|', '%', '&', '^', '<', '>', '[]', '[]='].each do |meth|
|
91
|
+
it "should work with #{meth}" do
|
92
|
+
Object.send :define_method, :meth_with_special_char do
|
93
|
+
meth
|
94
|
+
end
|
95
|
+
|
96
|
+
klass = Class.new do
|
97
|
+
aspector :class_methods => true do
|
98
|
+
before meth_with_special_char, :do_this
|
99
|
+
end
|
100
|
+
|
101
|
+
class << self
|
102
|
+
def value
|
103
|
+
@value ||= []
|
104
|
+
end
|
105
|
+
|
106
|
+
def do_this *args
|
107
|
+
value << "do_this"
|
108
|
+
end
|
109
|
+
|
110
|
+
define_method meth_with_special_char do |*args|
|
111
|
+
value << "test"
|
112
|
+
end
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
klass.send meth_with_special_char, 1, 2
|
117
|
+
klass.value.should == %w"do_this test"
|
118
|
+
end
|
119
|
+
end
|
120
|
+
|
121
|
+
end
|
122
|
+
|
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.12.
|
4
|
+
version: 0.12.2
|
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-07-
|
12
|
+
date: 2012-07-03 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rspec
|
@@ -268,7 +268,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
268
268
|
version: '0'
|
269
269
|
segments:
|
270
270
|
- 0
|
271
|
-
hash:
|
271
|
+
hash: 2407230077532113164
|
272
272
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
273
273
|
none: false
|
274
274
|
requirements:
|