binding_of_caller 0.6.6 → 0.6.7
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.
- data/README.md +5 -3
- data/Rakefile +0 -12
- data/binding_of_caller.gemspec +3 -3
- data/lib/binding_of_caller.rb +17 -18
- data/lib/binding_of_caller/version.rb +1 -1
- data/test/test_binding_of_caller.rb +108 -91
- metadata +41 -62
data/README.md
CHANGED
@@ -1,9 +1,11 @@
|
|
1
|
+
[](http://travis-ci.org/banister/binding_of_caller)
|
2
|
+
|
1
3
|
binding_of_caller
|
2
4
|
===========
|
3
5
|
|
4
6
|
(C) John Mair (banisterfiend) 2011
|
5
7
|
|
6
|
-
_Retrieve the binding of a method's caller in MRI 1.9.2
|
8
|
+
_Retrieve the binding of a method's caller in MRI 1.9.2+, and RBX (Rubinius)_
|
7
9
|
|
8
10
|
The `binding_of_caller` gem provides the `Binding#of_caller` method.
|
9
11
|
|
@@ -13,7 +15,7 @@ call stack, not limited to just the immediate caller.
|
|
13
15
|
|
14
16
|
**Recommended for use only in debugging situations. Do not use this in production apps.**
|
15
17
|
|
16
|
-
**Only works in MRI Ruby 1.9.2
|
18
|
+
**Only works in MRI Ruby 1.9.2, 1.9.3 and RBX (Rubinius)**
|
17
19
|
|
18
20
|
* Install the [gem](https://rubygems.org/gems/binding_of_caller): `gem install binding_of_caller`
|
19
21
|
* See the [source code](http://github.com/banister/binding_of_caller)
|
@@ -50,7 +52,7 @@ This project is a spinoff from the [Pry REPL project.](http://pry.github.com)
|
|
50
52
|
Features and limitations
|
51
53
|
-------------------------
|
52
54
|
|
53
|
-
* Only works with MRI 1.9.2
|
55
|
+
* Only works with MRI 1.9.2, 1.9.3 and RBX (Rubinius)
|
54
56
|
* Does not work in 1.8.7, but there is a well known (continuation-based) hack to get a `Binding#of_caller` there.
|
55
57
|
|
56
58
|
Contact
|
data/Rakefile
CHANGED
@@ -83,18 +83,6 @@ namespace :ruby do
|
|
83
83
|
end
|
84
84
|
end
|
85
85
|
|
86
|
-
# namespace :rbx do
|
87
|
-
# spec = Gem::Specification.new do |s|
|
88
|
-
# apply_spec_defaults(s)
|
89
|
-
# s.platform = Gem::Platform::RUBY #.new(["universal", "rubinius"])
|
90
|
-
# end
|
91
|
-
|
92
|
-
# Gem::PackageTask.new(spec) do |pkg|
|
93
|
-
# pkg.need_zip = false
|
94
|
-
# pkg.need_tar = false
|
95
|
-
# end
|
96
|
-
# end
|
97
|
-
|
98
86
|
desc "build the binaries"
|
99
87
|
task :compile do
|
100
88
|
chdir "./ext/#{PROJECT_NAME}/" do
|
data/binding_of_caller.gemspec
CHANGED
@@ -2,18 +2,18 @@
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |s|
|
4
4
|
s.name = "binding_of_caller"
|
5
|
-
s.version = "0.6.
|
5
|
+
s.version = "0.6.7"
|
6
6
|
|
7
7
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
8
8
|
s.authors = ["John Mair (banisterfiend)"]
|
9
|
-
s.date = "2012-03-
|
9
|
+
s.date = "2012-03-06"
|
10
10
|
s.description = "Retrieve the binding of a method's caller. Can also retrieve bindings even further up the stack."
|
11
11
|
s.email = "jrmair@gmail.com"
|
12
12
|
s.extensions = ["ext/binding_of_caller/extconf.rb"]
|
13
13
|
s.files = [".gemtest", ".gitignore", ".travis.yml", ".yardopts", "Gemfile", "HISTORY", "LICENSE", "README.md", "Rakefile", "binding_of_caller.gemspec", "examples/example.rb", "ext/binding_of_caller/binding_of_caller.c", "ext/binding_of_caller/extconf.rb", "ext/binding_of_caller/ruby_headers/192/debug.h", "ext/binding_of_caller/ruby_headers/192/dln.h", "ext/binding_of_caller/ruby_headers/192/eval_intern.h", "ext/binding_of_caller/ruby_headers/192/gc.h", "ext/binding_of_caller/ruby_headers/192/id.h", "ext/binding_of_caller/ruby_headers/192/iseq.h", "ext/binding_of_caller/ruby_headers/192/method.h", "ext/binding_of_caller/ruby_headers/192/node.h", "ext/binding_of_caller/ruby_headers/192/regenc.h", "ext/binding_of_caller/ruby_headers/192/regint.h", "ext/binding_of_caller/ruby_headers/192/regparse.h", "ext/binding_of_caller/ruby_headers/192/thread_pthread.h", "ext/binding_of_caller/ruby_headers/192/thread_win32.h", "ext/binding_of_caller/ruby_headers/192/timev.h", "ext/binding_of_caller/ruby_headers/192/transcode_data.h", "ext/binding_of_caller/ruby_headers/192/version.h", "ext/binding_of_caller/ruby_headers/192/vm_core.h", "ext/binding_of_caller/ruby_headers/192/vm_exec.h", "ext/binding_of_caller/ruby_headers/192/vm_insnhelper.h", "ext/binding_of_caller/ruby_headers/192/vm_opts.h", "ext/binding_of_caller/ruby_headers/193/addr2line.h", "ext/binding_of_caller/ruby_headers/193/atomic.h", "ext/binding_of_caller/ruby_headers/193/constant.h", "ext/binding_of_caller/ruby_headers/193/debug.h", "ext/binding_of_caller/ruby_headers/193/dln.h", "ext/binding_of_caller/ruby_headers/193/encdb.h", "ext/binding_of_caller/ruby_headers/193/eval_intern.h", "ext/binding_of_caller/ruby_headers/193/gc.h", "ext/binding_of_caller/ruby_headers/193/id.h", "ext/binding_of_caller/ruby_headers/193/internal.h", "ext/binding_of_caller/ruby_headers/193/iseq.h", "ext/binding_of_caller/ruby_headers/193/method.h", "ext/binding_of_caller/ruby_headers/193/node.h", "ext/binding_of_caller/ruby_headers/193/parse.h", "ext/binding_of_caller/ruby_headers/193/regenc.h", "ext/binding_of_caller/ruby_headers/193/regint.h", "ext/binding_of_caller/ruby_headers/193/regparse.h", "ext/binding_of_caller/ruby_headers/193/revision.h", "ext/binding_of_caller/ruby_headers/193/thread_pthread.h", "ext/binding_of_caller/ruby_headers/193/thread_win32.h", "ext/binding_of_caller/ruby_headers/193/timev.h", "ext/binding_of_caller/ruby_headers/193/transcode_data.h", "ext/binding_of_caller/ruby_headers/193/transdb.h", "ext/binding_of_caller/ruby_headers/193/version.h", "ext/binding_of_caller/ruby_headers/193/vm_core.h", "ext/binding_of_caller/ruby_headers/193/vm_exec.h", "ext/binding_of_caller/ruby_headers/193/vm_insnhelper.h", "ext/binding_of_caller/ruby_headers/193/vm_opts.h", "lib/binding_of_caller.rb", "lib/binding_of_caller/version.rb", "test/test_binding_of_caller.rb"]
|
14
14
|
s.homepage = "http://github.com/banister/binding_of_caller"
|
15
15
|
s.require_paths = ["lib"]
|
16
|
-
s.rubygems_version = "1.8.
|
16
|
+
s.rubygems_version = "1.8.16"
|
17
17
|
s.summary = "Retrieve the binding of a method's caller. Can also retrieve bindings even further up the stack."
|
18
18
|
s.test_files = ["test/test_binding_of_caller.rb"]
|
19
19
|
|
data/lib/binding_of_caller.rb
CHANGED
@@ -1,13 +1,15 @@
|
|
1
1
|
dlext = RbConfig::CONFIG['DLEXT']
|
2
2
|
direc = File.dirname(__FILE__)
|
3
3
|
|
4
|
-
if RUBY_ENGINE && RUBY_ENGINE == "ruby"
|
4
|
+
if defined?(RUBY_ENGINE) && RUBY_ENGINE == "ruby"
|
5
5
|
require "binding_of_caller.#{dlext}"
|
6
6
|
|
7
7
|
elsif defined?(Rubinius)
|
8
8
|
module BindingOfCaller
|
9
9
|
module BindingExtensions
|
10
10
|
|
11
|
+
# Retrieve the binding of the nth caller of the current frame.
|
12
|
+
# @return [Binding]
|
11
13
|
def of_caller(n)
|
12
14
|
bt = Rubinius::VM.backtrace(1 + n, true).first
|
13
15
|
|
@@ -26,41 +28,38 @@ elsif defined?(Rubinius)
|
|
26
28
|
raise RuntimeError, "Invalid frame, gone beyond end of stack!"
|
27
29
|
end
|
28
30
|
|
31
|
+
# The description of the frame.
|
32
|
+
# @return [String]
|
29
33
|
def frame_description
|
30
34
|
@frame_description
|
31
35
|
end
|
32
36
|
|
37
|
+
# Return bindings for all caller frames.
|
38
|
+
# @return [Array<Binding>]
|
33
39
|
def callers
|
34
40
|
ary = []
|
35
41
|
n = 0
|
36
|
-
loop
|
42
|
+
loop do
|
37
43
|
begin
|
38
44
|
ary << Binding.of_caller(n)
|
39
45
|
rescue
|
40
46
|
break
|
41
47
|
end
|
42
|
-
|
43
48
|
n += 1
|
44
|
-
|
45
|
-
|
46
|
-
|
49
|
+
end
|
50
|
+
ary.drop_while do |v|
|
51
|
+
!(v.frame_type == :method && v.eval("__method__") == :callers)
|
52
|
+
end.drop(1)
|
47
53
|
end
|
48
54
|
|
55
|
+
# Number of parent frames available at the point of call.
|
56
|
+
# @return [Fixnum]
|
49
57
|
def frame_count
|
50
|
-
|
51
|
-
loop {
|
52
|
-
begin
|
53
|
-
Binding.of_caller(n)
|
54
|
-
rescue
|
55
|
-
break
|
56
|
-
end
|
57
|
-
|
58
|
-
n += 1
|
59
|
-
}
|
60
|
-
|
61
|
-
n
|
58
|
+
callers.size - 1
|
62
59
|
end
|
63
60
|
|
61
|
+
# The type of the frame.
|
62
|
+
# @return [Symbol]
|
64
63
|
def frame_type
|
65
64
|
case self.variables.method.metadata.to_a.first.to_s
|
66
65
|
when /block/
|
@@ -1,91 +1,108 @@
|
|
1
|
-
unless Object.const_defined? :BindingOfCaller
|
2
|
-
$:.unshift File.expand_path '../../lib', __FILE__
|
3
|
-
require 'binding_of_caller'
|
4
|
-
require 'binding_of_caller/version'
|
5
|
-
end
|
6
|
-
|
7
|
-
puts "Testing binding_of_caller version #{BindingOfCaller::VERSION}..."
|
8
|
-
puts "Ruby version: #{RUBY_VERSION}"
|
9
|
-
|
10
|
-
describe BindingOfCaller do
|
11
|
-
describe "of_caller" do
|
12
|
-
it "should fetch immediate caller's binding when 0 is passed" do
|
13
|
-
o = Object.new
|
14
|
-
def o.a
|
15
|
-
var = 1
|
16
|
-
binding.of_caller(0).eval('var')
|
17
|
-
end
|
18
|
-
|
19
|
-
o. a.should == 1
|
20
|
-
end
|
21
|
-
|
22
|
-
it "should fetch parent of caller's binding when 1 is passed" do
|
23
|
-
o = Object.new
|
24
|
-
def o.a
|
25
|
-
var = 1
|
26
|
-
b
|
27
|
-
end
|
28
|
-
|
29
|
-
def o.b
|
30
|
-
binding.of_caller(1).eval('var')
|
31
|
-
end
|
32
|
-
|
33
|
-
o.a.should == 1
|
34
|
-
end
|
35
|
-
|
36
|
-
it "should modify locals in parent of caller's binding" do
|
37
|
-
o = Object.new
|
38
|
-
def o.a
|
39
|
-
var = 1
|
40
|
-
b
|
41
|
-
var
|
42
|
-
end
|
43
|
-
|
44
|
-
def o.b
|
45
|
-
binding.of_caller(1).eval('var = 20')
|
46
|
-
end
|
47
|
-
|
48
|
-
o.a.should == 20
|
49
|
-
end
|
50
|
-
|
51
|
-
it "should raise an exception when retrieving an out of band binding" do
|
52
|
-
o = Object.new
|
53
|
-
def o.a
|
54
|
-
binding.of_caller(100)
|
55
|
-
end
|
56
|
-
|
57
|
-
lambda { o.a }.should.raise RuntimeError
|
58
|
-
end
|
59
|
-
end
|
60
|
-
|
61
|
-
describe "
|
62
|
-
|
63
|
-
|
64
|
-
end
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
1
|
+
unless Object.const_defined? :BindingOfCaller
|
2
|
+
$:.unshift File.expand_path '../../lib', __FILE__
|
3
|
+
require 'binding_of_caller'
|
4
|
+
require 'binding_of_caller/version'
|
5
|
+
end
|
6
|
+
|
7
|
+
puts "Testing binding_of_caller version #{BindingOfCaller::VERSION}..."
|
8
|
+
puts "Ruby version: #{RUBY_VERSION}"
|
9
|
+
|
10
|
+
describe BindingOfCaller do
|
11
|
+
describe "of_caller" do
|
12
|
+
it "should fetch immediate caller's binding when 0 is passed" do
|
13
|
+
o = Object.new
|
14
|
+
def o.a
|
15
|
+
var = 1
|
16
|
+
binding.of_caller(0).eval('var')
|
17
|
+
end
|
18
|
+
|
19
|
+
o. a.should == 1
|
20
|
+
end
|
21
|
+
|
22
|
+
it "should fetch parent of caller's binding when 1 is passed" do
|
23
|
+
o = Object.new
|
24
|
+
def o.a
|
25
|
+
var = 1
|
26
|
+
b
|
27
|
+
end
|
28
|
+
|
29
|
+
def o.b
|
30
|
+
binding.of_caller(1).eval('var')
|
31
|
+
end
|
32
|
+
|
33
|
+
o.a.should == 1
|
34
|
+
end
|
35
|
+
|
36
|
+
it "should modify locals in parent of caller's binding" do
|
37
|
+
o = Object.new
|
38
|
+
def o.a
|
39
|
+
var = 1
|
40
|
+
b
|
41
|
+
var
|
42
|
+
end
|
43
|
+
|
44
|
+
def o.b
|
45
|
+
binding.of_caller(1).eval('var = 20')
|
46
|
+
end
|
47
|
+
|
48
|
+
o.a.should == 20
|
49
|
+
end
|
50
|
+
|
51
|
+
it "should raise an exception when retrieving an out of band binding" do
|
52
|
+
o = Object.new
|
53
|
+
def o.a
|
54
|
+
binding.of_caller(100)
|
55
|
+
end
|
56
|
+
|
57
|
+
lambda { o.a }.should.raise RuntimeError
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
describe "callers" do
|
62
|
+
before do
|
63
|
+
@o = Object.new
|
64
|
+
end
|
65
|
+
|
66
|
+
it 'should return the first non-internal binding when using callers.first' do
|
67
|
+
def @o.meth
|
68
|
+
x = :a_local
|
69
|
+
[binding.callers.first, binding.of_caller(0)]
|
70
|
+
end
|
71
|
+
|
72
|
+
b1, b2 = @o.meth
|
73
|
+
b1.eval("x").should == :a_local
|
74
|
+
b2.eval("x").should == :a_local
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
describe "frame_count" do
|
79
|
+
it 'frame_count should equal callers.count' do
|
80
|
+
binding.frame_count.should == binding.callers.count
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
describe "frame_type" do
|
85
|
+
it 'should return the correct frame types' do
|
86
|
+
o = Object.new
|
87
|
+
|
88
|
+
# method frame
|
89
|
+
def o.a
|
90
|
+
b
|
91
|
+
end
|
92
|
+
|
93
|
+
# method frame
|
94
|
+
def o.b
|
95
|
+
# block frame
|
96
|
+
proc do
|
97
|
+
binding.callers
|
98
|
+
end.call
|
99
|
+
end
|
100
|
+
caller_bindings = o.a
|
101
|
+
caller_bindings[0].frame_type.should == :block
|
102
|
+
caller_bindings[1].frame_type.should == :method
|
103
|
+
caller_bindings[2].frame_type.should == :method
|
104
|
+
end
|
105
|
+
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
metadata
CHANGED
@@ -1,59 +1,46 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: binding_of_caller
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.6.7
|
5
5
|
prerelease:
|
6
|
-
segments:
|
7
|
-
- 0
|
8
|
-
- 6
|
9
|
-
- 6
|
10
|
-
version: 0.6.6
|
11
6
|
platform: ruby
|
12
|
-
authors:
|
7
|
+
authors:
|
13
8
|
- John Mair (banisterfiend)
|
14
9
|
autorequire:
|
15
10
|
bindir: bin
|
16
11
|
cert_chain: []
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
- !ruby/object:Gem::Dependency
|
12
|
+
date: 2012-03-06 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
21
15
|
name: bacon
|
22
|
-
|
23
|
-
requirement: &id001 !ruby/object:Gem::Requirement
|
16
|
+
requirement: &70355084206460 !ruby/object:Gem::Requirement
|
24
17
|
none: false
|
25
|
-
requirements:
|
26
|
-
- -
|
27
|
-
- !ruby/object:Gem::Version
|
28
|
-
|
29
|
-
segments:
|
30
|
-
- 0
|
31
|
-
version: "0"
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
32
22
|
type: :development
|
33
|
-
version_requirements: *id001
|
34
|
-
- !ruby/object:Gem::Dependency
|
35
|
-
name: rake
|
36
23
|
prerelease: false
|
37
|
-
|
24
|
+
version_requirements: *70355084206460
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: rake
|
27
|
+
requirement: &70355084206040 !ruby/object:Gem::Requirement
|
38
28
|
none: false
|
39
|
-
requirements:
|
40
|
-
- -
|
41
|
-
- !ruby/object:Gem::Version
|
42
|
-
|
43
|
-
segments:
|
44
|
-
- 0
|
45
|
-
version: "0"
|
29
|
+
requirements:
|
30
|
+
- - ! '>='
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '0'
|
46
33
|
type: :development
|
47
|
-
|
48
|
-
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: *70355084206040
|
36
|
+
description: Retrieve the binding of a method's caller. Can also retrieve bindings
|
37
|
+
even further up the stack.
|
49
38
|
email: jrmair@gmail.com
|
50
39
|
executables: []
|
51
|
-
|
52
|
-
extensions:
|
40
|
+
extensions:
|
53
41
|
- ext/binding_of_caller/extconf.rb
|
54
42
|
extra_rdoc_files: []
|
55
|
-
|
56
|
-
files:
|
43
|
+
files:
|
57
44
|
- .gemtest
|
58
45
|
- .gitignore
|
59
46
|
- .travis.yml
|
@@ -120,36 +107,28 @@ files:
|
|
120
107
|
- test/test_binding_of_caller.rb
|
121
108
|
homepage: http://github.com/banister/binding_of_caller
|
122
109
|
licenses: []
|
123
|
-
|
124
110
|
post_install_message:
|
125
111
|
rdoc_options: []
|
126
|
-
|
127
|
-
require_paths:
|
112
|
+
require_paths:
|
128
113
|
- lib
|
129
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
114
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
130
115
|
none: false
|
131
|
-
requirements:
|
132
|
-
- -
|
133
|
-
- !ruby/object:Gem::Version
|
134
|
-
|
135
|
-
|
136
|
-
- 0
|
137
|
-
version: "0"
|
138
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
116
|
+
requirements:
|
117
|
+
- - ! '>='
|
118
|
+
- !ruby/object:Gem::Version
|
119
|
+
version: '0'
|
120
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
139
121
|
none: false
|
140
|
-
requirements:
|
141
|
-
- -
|
142
|
-
- !ruby/object:Gem::Version
|
143
|
-
|
144
|
-
segments:
|
145
|
-
- 0
|
146
|
-
version: "0"
|
122
|
+
requirements:
|
123
|
+
- - ! '>='
|
124
|
+
- !ruby/object:Gem::Version
|
125
|
+
version: '0'
|
147
126
|
requirements: []
|
148
|
-
|
149
127
|
rubyforge_project:
|
150
|
-
rubygems_version: 1.8.
|
128
|
+
rubygems_version: 1.8.16
|
151
129
|
signing_key:
|
152
130
|
specification_version: 3
|
153
|
-
summary: Retrieve the binding of a method's caller. Can also retrieve bindings even
|
154
|
-
|
131
|
+
summary: Retrieve the binding of a method's caller. Can also retrieve bindings even
|
132
|
+
further up the stack.
|
133
|
+
test_files:
|
155
134
|
- test/test_binding_of_caller.rb
|