peeek 1.0.2 → 1.0.3

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 90ae3ee8f84b1d47140d8ebd28943835875550be
4
- data.tar.gz: 8a7bdc5de0df596be2e309ee950112e89ff94166
3
+ metadata.gz: 4cf3690abfc7e18ba772e5813bd248c6e8f77e31
4
+ data.tar.gz: 97b35ef5d8c535fc08db01336fbc0ee319be02f9
5
5
  SHA512:
6
- metadata.gz: f6ffdc7048653dc766511b66272c730a1f37ac04a1aa7efe35efa4a834916f758d5766ad5c07da75954cb5a63c4a067788014514ca2edcd94756654f5b13dc75
7
- data.tar.gz: d32b0ca28b0520cf773aa1f1f22c678168cdf6211dcac657796d1dc73fd85819db714df49e7e2ca8c4a9cd8fa78b1a62f80818afbddd3fb9c786c44649ef55e3
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.local` return an instance of `Peeek::Calls`. It has
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'
@@ -118,7 +118,11 @@ class Peeek
118
118
 
119
119
  # Link the hook to the method.
120
120
  def link
121
- @original_method = @linker.link(&method(:call)) unless linked?
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
 
@@ -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.
@@ -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.
@@ -1,3 +1,3 @@
1
1
  class Peeek
2
- VERSION = '1.0.2'
2
+ VERSION = '1.0.3'
3
3
  end
@@ -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
@@ -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
@@ -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', :link => original_method, :unlink => nil)
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.2
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-08 00:00:00.000000000 Z
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.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