evalhook 0.5.4 → 0.5.5

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG CHANGED
@@ -1,3 +1,9 @@
1
+ 0.5.5 Fixed handling of method_missing
2
+
3
+ 0.5.4 Fixed release issues
4
+
5
+ 0.5.3 Added license to gemspec
6
+
1
7
  0.5.1 Fixed compatibility issues with sexp_processor, ruby_parser and ruby2ruby
2
8
 
3
9
  0.5.0 Implemented code packets (see documentation)
data/Rakefile CHANGED
@@ -6,7 +6,7 @@ require 'rake/testtask'
6
6
 
7
7
  spec = Gem::Specification.new do |s|
8
8
  s.name = 'evalhook'
9
- s.version = '0.5.4'
9
+ s.version = '0.5.5'
10
10
  s.author = 'Dario Seminara'
11
11
  s.email = 'robertodarioseminara@gmail.com'
12
12
  s.platform = Gem::Platform::RUBY
data/lib/evalhook.rb CHANGED
@@ -139,8 +139,15 @@ module EvalHook
139
139
 
140
140
  def hooked_method(receiver, mname, klass = nil) #:nodoc:
141
141
  m = nil
142
+ is_method_missing = false
143
+
142
144
  unless klass
143
- m = receiver.method(mname)
145
+ m = begin
146
+ receiver.method(mname)
147
+ rescue
148
+ is_method_missing = true
149
+ receiver.public_method(:method_missing)
150
+ end
144
151
  klass = m.owner
145
152
  else
146
153
  m = klass.instance_method(mname).bind(receiver)
@@ -160,6 +167,10 @@ module EvalHook
160
167
  end
161
168
  end
162
169
 
170
+ if is_method_missing
171
+ orig_m = m
172
+ m = lambda{|*x| orig_m.call(mname,*x) }
173
+ end
163
174
  m
164
175
  end
165
176
 
@@ -168,7 +179,14 @@ module EvalHook
168
179
  if local_vars.include? mname.to_s
169
180
  HookedCallValue.new( _binding.eval(mname.to_s) )
170
181
  else
171
- m = receiver.method(mname)
182
+ is_method_missing = false
183
+ m = begin
184
+ receiver.method(mname)
185
+ rescue
186
+ is_method_missing = true
187
+ receiver.method(:method_missing)
188
+ end
189
+
172
190
  klass = m.owner
173
191
  ret = handle_method(klass, receiver, mname )
174
192
 
@@ -184,6 +202,10 @@ module EvalHook
184
202
  end
185
203
  end
186
204
 
205
+ if is_method_missing
206
+ orig_m = m
207
+ m = lambda{|*x| orig_m.call(mname,*x) }
208
+ end
187
209
  m
188
210
  end
189
211
  end
@@ -285,7 +307,15 @@ module EvalHook
285
307
  end
286
308
 
287
309
  def private_method_check(recv, mname)
288
- recv.public_method(mname) rescue NameError raise NoMethodError
310
+ begin
311
+ recv.public_method(mname)
312
+ rescue NameError
313
+ begin
314
+ recv.public_method(:method_missing)
315
+ rescue NameError
316
+ raise NoMethodError
317
+ end
318
+ end
289
319
  recv
290
320
  end
291
321
 
@@ -3,7 +3,7 @@ require "evalhook"
3
3
 
4
4
  describe EvalHook::HookHandler, "hook handler hooks" do
5
5
 
6
- it "should raise NoMethodError when tring to call private method" do
6
+ it "should raise NoMethodError when trying to call private method" do
7
7
  hh = EvalHook::HookHandler.new
8
8
  lambda {
9
9
  hh.evalhook("{}.system('ls -l')", binding)
@@ -11,7 +11,7 @@ describe EvalHook::HookHandler, "hook handler hooks" do
11
11
  end
12
12
 
13
13
 
14
- it "should raise NoMethodError when tring to call private method" do
14
+ it "should raise NoMethodError when trying to call private method" do
15
15
  hh = EvalHook::HookHandler.new
16
16
  lambda {
17
17
  hh.evalhook("
@@ -29,4 +29,39 @@ describe EvalHook::HookHandler, "hook handler hooks" do
29
29
  }.should_not raise_error
30
30
  end
31
31
 
32
+ class XDefinedOutside55
33
+ def method_missing(name)
34
+ name
35
+ end
36
+ end
37
+ XDefinedOutside55_ins = XDefinedOutside55.new
38
+
39
+ context "when there is method_missing defined" do
40
+ it "shouldn't raise NoMethodError when trying to call a public method NOT defined" do
41
+ hh = EvalHook::HookHandler.new
42
+ lambda {
43
+ hh.evalhook("
44
+ XDefinedOutside55_ins.foo
45
+ ", binding).should be == :foo
46
+ }.should_not raise_error
47
+ end
48
+ end
49
+
50
+ class XDefinedOutside56
51
+ def method_missing(name, param1)
52
+ name
53
+ end
54
+ end
55
+ XDefinedOutside56_ins = XDefinedOutside56.new
56
+
57
+ context "when there is method_missing defined (two arguments)" do
58
+ it "shouldn't raise NoMethodError when trying to call a public method NOT defined" do
59
+ hh = EvalHook::HookHandler.new
60
+ lambda {
61
+ hh.evalhook("
62
+ XDefinedOutside56_ins.foo(1)
63
+ ", binding).should be == :foo
64
+ }.should_not raise_error
65
+ end
66
+ end
32
67
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: evalhook
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.4
4
+ version: 0.5.5
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-09-05 00:00:00.000000000 Z
12
+ date: 2013-09-14 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: partialruby
16
- requirement: &81627980 !ruby/object:Gem::Requirement
16
+ requirement: &71965870 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: 0.2.3
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *81627980
24
+ version_requirements: *71965870
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: ruby_parser
27
- requirement: &81627690 !ruby/object:Gem::Requirement
27
+ requirement: &71965480 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ~>
@@ -32,7 +32,7 @@ dependencies:
32
32
  version: '2.0'
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *81627690
35
+ version_requirements: *71965480
36
36
  description:
37
37
  email: robertodarioseminara@gmail.com
38
38
  executables: []