peeek 1.0.2 → 1.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/lib/peeek/hook.rb +5 -1
- data/lib/peeek/hook/instance.rb +6 -3
- data/lib/peeek/hook/singleton.rb +6 -3
- data/lib/peeek/version.rb +1 -1
- data/spec/peeek/hook/instance_spec.rb +9 -4
- data/spec/peeek/hook/singleton_spec.rb +9 -4
- data/spec/peeek/hook_spec.rb +8 -0
- data/spec/spec_helper.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4cf3690abfc7e18ba772e5813bd248c6e8f77e31
|
4
|
+
data.tar.gz: 97b35ef5d8c535fc08db01336fbc0ee319be02f9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 19ddd27a103fe0c1c52484f1525e73743ed7755bdfbc323a3de52263bc4ba2aee2694280ac50ccdeb0d5fbac44d412812c3d745c44c560c81a594c1ed2fd767d
|
7
|
+
data.tar.gz: 31f272cd92df1acf44b5e16877a30c1c7975e0fec030322c7cb8308449b69ef421153af4b0cf8048eff5c9f4fa967b2e2eebc18f0c5793ce9be78d06bcf45b5a
|
data/README.md
CHANGED
@@ -96,7 +96,7 @@ Hook to methods at head of the block, and return the calls, then use
|
|
96
96
|
|
97
97
|
### Filter calls
|
98
98
|
|
99
|
-
`Peeek#calls` or `Peeek.
|
99
|
+
`Peeek#calls` or `Peeek.capture` return an instance of `Peeek::Calls`. It has
|
100
100
|
implemented methods to filter by attributes of the call.
|
101
101
|
|
102
102
|
require 'peeek'
|
data/lib/peeek/hook.rb
CHANGED
@@ -118,7 +118,11 @@ class Peeek
|
|
118
118
|
|
119
119
|
# Link the hook to the method.
|
120
120
|
def link
|
121
|
-
|
121
|
+
unless linked?
|
122
|
+
@original_method = @linker.target_method
|
123
|
+
@linker.link(&method(:call))
|
124
|
+
end
|
125
|
+
|
122
126
|
self
|
123
127
|
end
|
124
128
|
|
data/lib/peeek/hook/instance.rb
CHANGED
@@ -11,6 +11,12 @@ class Peeek
|
|
11
11
|
METHOD_PREFIX
|
12
12
|
end
|
13
13
|
|
14
|
+
# @attribute [r] target_method
|
15
|
+
# @return [UnboundMethod] the instance method of the object
|
16
|
+
def target_method
|
17
|
+
@object.instance_method(@method_name)
|
18
|
+
end
|
19
|
+
|
14
20
|
# Determine if the instance method is defined in the object.
|
15
21
|
#
|
16
22
|
# @return whether the instance method is defined in the object
|
@@ -25,12 +31,9 @@ class Peeek
|
|
25
31
|
# @yieldparam [Object] receiver object that received the call
|
26
32
|
# @yieldparam [Array] args arguments at the call
|
27
33
|
# @yieldreturn [Object] return value of the original method
|
28
|
-
# @return [UnboundMethod] the original method
|
29
34
|
def link
|
30
35
|
raise ArgumentError, 'block not supplied' unless block_given?
|
31
|
-
original_method = @object.instance_method(@method_name)
|
32
36
|
define_method { |*args| yield caller, self, args }
|
33
|
-
original_method
|
34
37
|
end
|
35
38
|
|
36
39
|
# Unlink the hook from the instance method.
|
data/lib/peeek/hook/singleton.rb
CHANGED
@@ -11,6 +11,12 @@ class Peeek
|
|
11
11
|
METHOD_PREFIX
|
12
12
|
end
|
13
13
|
|
14
|
+
# @attribute [r] target_method
|
15
|
+
# @return [Method] the method of the object
|
16
|
+
def target_method
|
17
|
+
@object.method(@method_name)
|
18
|
+
end
|
19
|
+
|
14
20
|
# Determine if the method is defined in the object.
|
15
21
|
#
|
16
22
|
# @return whether the method is defined in the object
|
@@ -25,12 +31,9 @@ class Peeek
|
|
25
31
|
# @yieldparam [Object] receiver object that received the call
|
26
32
|
# @yieldparam [Array] args arguments at the call
|
27
33
|
# @yieldreturn [Object] return value of the original method
|
28
|
-
# @return [Method] original method
|
29
34
|
def link
|
30
35
|
raise ArgumentError, 'block not supplied' unless block_given?
|
31
|
-
original_method = @object.method(@method_name)
|
32
36
|
define_method { |*args| yield caller, self, args }
|
33
|
-
original_method
|
34
37
|
end
|
35
38
|
|
36
39
|
# Unlink the hook from the method.
|
data/lib/peeek/version.rb
CHANGED
@@ -11,6 +11,15 @@ describe Peeek::Hook::Instance, '#method_prefix' do
|
|
11
11
|
end
|
12
12
|
end
|
13
13
|
|
14
|
+
describe Peeek::Hook::Instance, '#target_method' do
|
15
|
+
it 'returns the instance method of the object' do
|
16
|
+
linker = sample_instance_linker
|
17
|
+
method = linker.target_method
|
18
|
+
method.owner.should == String
|
19
|
+
method.name.should == :%
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
14
23
|
describe Peeek::Hook::Instance, '#defined?' do
|
15
24
|
it 'is true if the method is defined in the object' do
|
16
25
|
linker = sample_instance_linker
|
@@ -58,10 +67,6 @@ describe Peeek::Hook::Instance, '#link' do
|
|
58
67
|
lambda { '%s (%d)' % ['Koyomi', 18] }.should raise_error('exception')
|
59
68
|
end
|
60
69
|
|
61
|
-
it 'returns the original method' do
|
62
|
-
@linker.link { }.should == @original_method
|
63
|
-
end
|
64
|
-
|
65
70
|
it 'raises ArgumentError if a block not given' do
|
66
71
|
lambda { @linker.link }.should raise_error(ArgumentError, 'block not supplied')
|
67
72
|
end
|
@@ -11,6 +11,15 @@ describe Peeek::Hook::Singleton, '#method_prefix' do
|
|
11
11
|
end
|
12
12
|
end
|
13
13
|
|
14
|
+
describe Peeek::Hook::Singleton, '#target_method' do
|
15
|
+
it 'returns the method of the object' do
|
16
|
+
linker = sample_singleton_linker
|
17
|
+
method = linker.target_method
|
18
|
+
method.receiver.should == Regexp
|
19
|
+
method.name.should == :quote
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
14
23
|
describe Peeek::Hook::Singleton, '#defined?' do
|
15
24
|
it 'is true if the method is defined in the object' do
|
16
25
|
linker = sample_singleton_linker
|
@@ -53,10 +62,6 @@ describe Peeek::Hook::Singleton, '#link' do
|
|
53
62
|
lambda { Regexp.quote('.') }.should raise_error('exception')
|
54
63
|
end
|
55
64
|
|
56
|
-
it 'returns the original method' do
|
57
|
-
@linker.link { }.should == @original_method
|
58
|
-
end
|
59
|
-
|
60
65
|
it 'raises ArgumentError if a block not given' do
|
61
66
|
lambda { @linker.link }.should raise_error(ArgumentError, 'block not supplied')
|
62
67
|
end
|
data/spec/peeek/hook_spec.rb
CHANGED
@@ -182,6 +182,14 @@ describe Peeek::Hook, '#link' do
|
|
182
182
|
@hook.link
|
183
183
|
end
|
184
184
|
|
185
|
+
it "is linked before call #{described_class}::Linker#link" do
|
186
|
+
@linker.stub!(:link).with { }.and_return do |&block|
|
187
|
+
@hook.should be_linked
|
188
|
+
end
|
189
|
+
|
190
|
+
@hook.link
|
191
|
+
end
|
192
|
+
|
185
193
|
it 'links the hook to the method' do
|
186
194
|
@hook.should_not be_linked # assert
|
187
195
|
@hook.link
|
data/spec/spec_helper.rb
CHANGED
@@ -24,7 +24,7 @@ end
|
|
24
24
|
|
25
25
|
def instance_linker_stub(object, method_name)
|
26
26
|
original_method = object.instance_method(method_name)
|
27
|
-
linker = stub('Peeek::Hook::Linker', :
|
27
|
+
linker = stub('Peeek::Hook::Linker', :target_method => original_method, :link => nil, :unlink => nil)
|
28
28
|
[linker, original_method]
|
29
29
|
end
|
30
30
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: peeek
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Takahiro Kondo
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-04-
|
11
|
+
date: 2013-04-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
@@ -101,7 +101,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
101
101
|
version: '0'
|
102
102
|
requirements: []
|
103
103
|
rubyforge_project:
|
104
|
-
rubygems_version: 2.0.
|
104
|
+
rubygems_version: 2.0.3
|
105
105
|
signing_key:
|
106
106
|
specification_version: 4
|
107
107
|
summary: Peek at calls of a method
|