binding_of_caller 0.6.3-universal-rubinius

Sign up to get free protection for your applications and to get access to all the features.
Files changed (64) hide show
  1. data/.gemtest +0 -0
  2. data/.gitignore +7 -0
  3. data/.yardopts +1 -0
  4. data/HISTORY +0 -0
  5. data/LICENSE +25 -0
  6. data/README.md +86 -0
  7. data/Rakefile +112 -0
  8. data/examples/example.rb +41 -0
  9. data/ext/binding_of_caller/binding_of_caller.c +220 -0
  10. data/ext/binding_of_caller/extconf.rb +13 -0
  11. data/ext/binding_of_caller/ruby_headers/192/debug.h +36 -0
  12. data/ext/binding_of_caller/ruby_headers/192/dln.h +41 -0
  13. data/ext/binding_of_caller/ruby_headers/192/eval_intern.h +232 -0
  14. data/ext/binding_of_caller/ruby_headers/192/gc.h +77 -0
  15. data/ext/binding_of_caller/ruby_headers/192/id.h +173 -0
  16. data/ext/binding_of_caller/ruby_headers/192/iseq.h +104 -0
  17. data/ext/binding_of_caller/ruby_headers/192/method.h +103 -0
  18. data/ext/binding_of_caller/ruby_headers/192/node.h +483 -0
  19. data/ext/binding_of_caller/ruby_headers/192/regenc.h +211 -0
  20. data/ext/binding_of_caller/ruby_headers/192/regint.h +841 -0
  21. data/ext/binding_of_caller/ruby_headers/192/regparse.h +354 -0
  22. data/ext/binding_of_caller/ruby_headers/192/thread_pthread.h +27 -0
  23. data/ext/binding_of_caller/ruby_headers/192/thread_win32.h +33 -0
  24. data/ext/binding_of_caller/ruby_headers/192/timev.h +21 -0
  25. data/ext/binding_of_caller/ruby_headers/192/transcode_data.h +109 -0
  26. data/ext/binding_of_caller/ruby_headers/192/version.h +63 -0
  27. data/ext/binding_of_caller/ruby_headers/192/vm_core.h +703 -0
  28. data/ext/binding_of_caller/ruby_headers/192/vm_exec.h +184 -0
  29. data/ext/binding_of_caller/ruby_headers/192/vm_insnhelper.h +208 -0
  30. data/ext/binding_of_caller/ruby_headers/192/vm_opts.h +51 -0
  31. data/ext/binding_of_caller/ruby_headers/193/addr2line.h +21 -0
  32. data/ext/binding_of_caller/ruby_headers/193/atomic.h +56 -0
  33. data/ext/binding_of_caller/ruby_headers/193/constant.h +34 -0
  34. data/ext/binding_of_caller/ruby_headers/193/debug.h +41 -0
  35. data/ext/binding_of_caller/ruby_headers/193/dln.h +50 -0
  36. data/ext/binding_of_caller/ruby_headers/193/encdb.h +167 -0
  37. data/ext/binding_of_caller/ruby_headers/193/eval_intern.h +234 -0
  38. data/ext/binding_of_caller/ruby_headers/193/gc.h +98 -0
  39. data/ext/binding_of_caller/ruby_headers/193/id.h +175 -0
  40. data/ext/binding_of_caller/ruby_headers/193/internal.h +227 -0
  41. data/ext/binding_of_caller/ruby_headers/193/iseq.h +125 -0
  42. data/ext/binding_of_caller/ruby_headers/193/method.h +105 -0
  43. data/ext/binding_of_caller/ruby_headers/193/node.h +503 -0
  44. data/ext/binding_of_caller/ruby_headers/193/parse.h +186 -0
  45. data/ext/binding_of_caller/ruby_headers/193/regenc.h +219 -0
  46. data/ext/binding_of_caller/ruby_headers/193/regint.h +851 -0
  47. data/ext/binding_of_caller/ruby_headers/193/regparse.h +362 -0
  48. data/ext/binding_of_caller/ruby_headers/193/revision.h +1 -0
  49. data/ext/binding_of_caller/ruby_headers/193/thread_pthread.h +51 -0
  50. data/ext/binding_of_caller/ruby_headers/193/thread_win32.h +40 -0
  51. data/ext/binding_of_caller/ruby_headers/193/timev.h +21 -0
  52. data/ext/binding_of_caller/ruby_headers/193/transcode_data.h +117 -0
  53. data/ext/binding_of_caller/ruby_headers/193/transdb.h +189 -0
  54. data/ext/binding_of_caller/ruby_headers/193/version.h +52 -0
  55. data/ext/binding_of_caller/ruby_headers/193/vm_core.h +755 -0
  56. data/ext/binding_of_caller/ruby_headers/193/vm_exec.h +184 -0
  57. data/ext/binding_of_caller/ruby_headers/193/vm_insnhelper.h +220 -0
  58. data/ext/binding_of_caller/ruby_headers/193/vm_opts.h +51 -0
  59. data/lib/binding_of_caller.bundle +0 -0
  60. data/lib/binding_of_caller.rb +82 -0
  61. data/lib/binding_of_caller/version.rb +3 -0
  62. data/lib/tester.rb +15 -0
  63. data/test/test.rb +91 -0
  64. metadata +121 -0
Binary file
@@ -0,0 +1,82 @@
1
+ dlext = Config::CONFIG['DLEXT']
2
+
3
+ if RUBY_ENGINE && RUBY_ENGINE == "ruby"
4
+ require "binding_of_caller.#{dlext}"
5
+
6
+ elsif defined?(Rubinius)
7
+ module BindingOfCaller
8
+ module BindingExtensions
9
+
10
+ def of_caller(n)
11
+ bt = Rubinius::VM.backtrace(1 + n, true).first
12
+
13
+ b = Binding.setup(
14
+ bt.variables,
15
+ bt.variables.method,
16
+ bt.static_scope,
17
+ bt.variables.self,
18
+ bt
19
+ )
20
+
21
+ b.instance_variable_set(:@frame_description, bt.describe)
22
+
23
+ b
24
+ rescue
25
+ raise RuntimeError, "Invalid frame, gone beyond end of stack!"
26
+ end
27
+
28
+ def frame_description
29
+ @frame_description
30
+ end
31
+
32
+ def callers
33
+ ary = []
34
+ n = 0
35
+ loop {
36
+ begin
37
+ ary << Binding.of_caller(n)
38
+ rescue
39
+ break
40
+ end
41
+
42
+ n += 1
43
+ }
44
+
45
+ ary
46
+ end
47
+
48
+ def frame_count
49
+ ary = []
50
+ n = 1
51
+ loop {
52
+ begin
53
+ Binding.of_caller(n)
54
+ rescue
55
+ break
56
+ end
57
+
58
+ n += 1
59
+ }
60
+
61
+ n
62
+ end
63
+
64
+ def frame_type
65
+ case self.variables.method.metadata.to_a.first.to_s
66
+ when /block/
67
+ :block
68
+ when /eval/
69
+ :eval
70
+ else
71
+ :method
72
+ end
73
+ end
74
+
75
+ end
76
+ end
77
+
78
+ class ::Binding
79
+ include BindingOfCaller::BindingExtensions
80
+ extend BindingOfCaller::BindingExtensions
81
+ end
82
+ end
@@ -0,0 +1,3 @@
1
+ module BindingOfCaller
2
+ VERSION = "0.6.3"
3
+ end
data/lib/tester.rb ADDED
@@ -0,0 +1,15 @@
1
+ require './binding_of_caller'
2
+
3
+ def a
4
+ x = 1
5
+ y = 2
6
+ b()
7
+ end
8
+
9
+ def b
10
+ proc do
11
+ puts binding.of_caller(2).eval('__method__')
12
+ end.call
13
+ end
14
+
15
+ a
data/test/test.rb ADDED
@@ -0,0 +1,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 "frame_count" do
62
+ it 'frame_count should equal callers.count' do
63
+ binding.frame_count.should == binding.callers.count
64
+ end
65
+ end
66
+
67
+ describe "frame_type" do
68
+ it 'should return the correct frame types' do
69
+ o = Object.new
70
+
71
+ # method frame
72
+ def o.a
73
+ b
74
+ end
75
+
76
+ # method frame
77
+ def o.b
78
+ # block frame
79
+ proc do
80
+ binding.callers
81
+ end.call
82
+ end
83
+ caller_bindings = o.a
84
+ caller_bindings[0].frame_type.should == :block
85
+ caller_bindings[1].frame_type.should == :method
86
+ caller_bindings[2].frame_type.should == :method
87
+ end
88
+
89
+ end
90
+ end
91
+
metadata ADDED
@@ -0,0 +1,121 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: binding_of_caller
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.6.3
5
+ prerelease:
6
+ platform: universal-rubinius
7
+ authors:
8
+ - John Mair (banisterfiend)
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-02-29 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: bacon
16
+ requirement: &70210333918260 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: '1.1'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: *70210333918260
25
+ description: Retrieve the binding of a method's caller. Can also retrieve bindings
26
+ even further up the stack. Currently only works for MRI 1.9.2+
27
+ email: jrmair@gmail.com
28
+ executables: []
29
+ extensions: []
30
+ extra_rdoc_files: []
31
+ files:
32
+ - .gemtest
33
+ - .gitignore
34
+ - .yardopts
35
+ - HISTORY
36
+ - LICENSE
37
+ - README.md
38
+ - Rakefile
39
+ - examples/example.rb
40
+ - ext/binding_of_caller/binding_of_caller.c
41
+ - ext/binding_of_caller/extconf.rb
42
+ - ext/binding_of_caller/ruby_headers/192/debug.h
43
+ - ext/binding_of_caller/ruby_headers/192/dln.h
44
+ - ext/binding_of_caller/ruby_headers/192/eval_intern.h
45
+ - ext/binding_of_caller/ruby_headers/192/gc.h
46
+ - ext/binding_of_caller/ruby_headers/192/id.h
47
+ - ext/binding_of_caller/ruby_headers/192/iseq.h
48
+ - ext/binding_of_caller/ruby_headers/192/method.h
49
+ - ext/binding_of_caller/ruby_headers/192/node.h
50
+ - ext/binding_of_caller/ruby_headers/192/regenc.h
51
+ - ext/binding_of_caller/ruby_headers/192/regint.h
52
+ - ext/binding_of_caller/ruby_headers/192/regparse.h
53
+ - ext/binding_of_caller/ruby_headers/192/thread_pthread.h
54
+ - ext/binding_of_caller/ruby_headers/192/thread_win32.h
55
+ - ext/binding_of_caller/ruby_headers/192/timev.h
56
+ - ext/binding_of_caller/ruby_headers/192/transcode_data.h
57
+ - ext/binding_of_caller/ruby_headers/192/version.h
58
+ - ext/binding_of_caller/ruby_headers/192/vm_core.h
59
+ - ext/binding_of_caller/ruby_headers/192/vm_exec.h
60
+ - ext/binding_of_caller/ruby_headers/192/vm_insnhelper.h
61
+ - ext/binding_of_caller/ruby_headers/192/vm_opts.h
62
+ - ext/binding_of_caller/ruby_headers/193/addr2line.h
63
+ - ext/binding_of_caller/ruby_headers/193/atomic.h
64
+ - ext/binding_of_caller/ruby_headers/193/constant.h
65
+ - ext/binding_of_caller/ruby_headers/193/debug.h
66
+ - ext/binding_of_caller/ruby_headers/193/dln.h
67
+ - ext/binding_of_caller/ruby_headers/193/encdb.h
68
+ - ext/binding_of_caller/ruby_headers/193/eval_intern.h
69
+ - ext/binding_of_caller/ruby_headers/193/gc.h
70
+ - ext/binding_of_caller/ruby_headers/193/id.h
71
+ - ext/binding_of_caller/ruby_headers/193/internal.h
72
+ - ext/binding_of_caller/ruby_headers/193/iseq.h
73
+ - ext/binding_of_caller/ruby_headers/193/method.h
74
+ - ext/binding_of_caller/ruby_headers/193/node.h
75
+ - ext/binding_of_caller/ruby_headers/193/parse.h
76
+ - ext/binding_of_caller/ruby_headers/193/regenc.h
77
+ - ext/binding_of_caller/ruby_headers/193/regint.h
78
+ - ext/binding_of_caller/ruby_headers/193/regparse.h
79
+ - ext/binding_of_caller/ruby_headers/193/revision.h
80
+ - ext/binding_of_caller/ruby_headers/193/thread_pthread.h
81
+ - ext/binding_of_caller/ruby_headers/193/thread_win32.h
82
+ - ext/binding_of_caller/ruby_headers/193/timev.h
83
+ - ext/binding_of_caller/ruby_headers/193/transcode_data.h
84
+ - ext/binding_of_caller/ruby_headers/193/transdb.h
85
+ - ext/binding_of_caller/ruby_headers/193/version.h
86
+ - ext/binding_of_caller/ruby_headers/193/vm_core.h
87
+ - ext/binding_of_caller/ruby_headers/193/vm_exec.h
88
+ - ext/binding_of_caller/ruby_headers/193/vm_insnhelper.h
89
+ - ext/binding_of_caller/ruby_headers/193/vm_opts.h
90
+ - lib/binding_of_caller.bundle
91
+ - lib/binding_of_caller.rb
92
+ - lib/binding_of_caller/version.rb
93
+ - lib/tester.rb
94
+ - test/test.rb
95
+ homepage: http://github.com/banister/binding_of_caller
96
+ licenses: []
97
+ post_install_message:
98
+ rdoc_options: []
99
+ require_paths:
100
+ - lib
101
+ required_ruby_version: !ruby/object:Gem::Requirement
102
+ none: false
103
+ requirements:
104
+ - - ! '>='
105
+ - !ruby/object:Gem::Version
106
+ version: '0'
107
+ required_rubygems_version: !ruby/object:Gem::Requirement
108
+ none: false
109
+ requirements:
110
+ - - ! '>='
111
+ - !ruby/object:Gem::Version
112
+ version: '0'
113
+ requirements: []
114
+ rubyforge_project:
115
+ rubygems_version: 1.8.16
116
+ signing_key:
117
+ specification_version: 3
118
+ summary: Retrieve the binding of a method's caller. Can also retrieve bindings even
119
+ further up the stack. Currently only works for MRI 1.9.2+
120
+ test_files:
121
+ - test/test.rb