binding_of_caller 0.7.1 → 0.7.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: eb405aa7190a04a128baff727db90ef40ae1468c
4
- data.tar.gz: 43cc746def25b335c279df78b070d926bdb43ebc
3
+ metadata.gz: f3fb3c7ee20b9b9ca1237d0540c2768efc657111
4
+ data.tar.gz: be4845aeca79432000b44be789993c23c1955715
5
5
  SHA512:
6
- metadata.gz: 2352e3c209510a9bed92399403425165c3b18bdaa559803d6a042ff5b98b52e70fb9b299236dad9d9895e06b533bcee7a3f1952bd8e7fea972d944b244e8e345
7
- data.tar.gz: 7e47b06c1867cec238f1a772a8659acc738b328fd4425601b7a0bb7ce55925be0ebbbee43709bc453efef4ba41e989eed560d6ed7232fc030b83b2c17185910a
6
+ metadata.gz: 3fd5d2a9ffbda43fcc2d8afa739ec51052f5dacc8632c3e88b60b7be90c2bd67c8a813156dab341e9f3399e46db667f3a1246043d50f1f60b6654d5c07e4e93c
7
+ data.tar.gz: 13fe3b6ab87052403c99be357fb91ea3ed2c9e9e5a8bafadc3123293bbb0a47bd7a235c67f7d25adb020f07bef0dee6d5a00424c7f59bf4c8b59dfc1f691d5c8
data/.gitignore CHANGED
@@ -1,7 +1,8 @@
1
- Makefile
2
- *.so
3
- *.o
4
- *.def
5
- doc/
6
- pkg/
7
- .yardoc/
1
+ Makefile
2
+ *.so
3
+ *.o
4
+ *.def
5
+ doc/
6
+ pkg/
7
+ .yardoc/
8
+ Gemfile.lock
@@ -1,7 +1,8 @@
1
1
  rvm:
2
2
  - 1.9.2
3
3
  - 1.9.3
4
- - ruby-head
4
+ - 2.0.0
5
+ - rbx-19mode
5
6
 
6
7
  notifications:
7
8
  irc: "irc.freenode.org#pry"
data/Gemfile CHANGED
@@ -1,2 +1,2 @@
1
- source :rubygems
1
+ source 'https://rubygems.org'
2
2
  gemspec
data/README.md CHANGED
@@ -3,9 +3,9 @@
3
3
  binding_of_caller
4
4
  ===========
5
5
 
6
- (C) John Mair (banisterfiend) 2011
6
+ (C) John Mair (banisterfiend) 2012
7
7
 
8
- _Retrieve the binding of a method's caller in MRI 1.9.2+, and RBX (Rubinius)_
8
+ _Retrieve the binding of a method's caller in MRI 1.9.2+, MRI 2.0 and RBX (Rubinius)_
9
9
 
10
10
  The `binding_of_caller` gem provides the `Binding#of_caller` method.
11
11
 
@@ -15,7 +15,7 @@ call stack, not limited to just the immediate caller.
15
15
 
16
16
  **Recommended for use only in debugging situations. Do not use this in production apps.**
17
17
 
18
- **Only works in MRI Ruby 1.9.2, 1.9.3 and RBX (Rubinius)**
18
+ **Only works in MRI Ruby 1.9.2, 1.9.3, 2.0 and RBX (Rubinius)**
19
19
 
20
20
  * Install the [gem](https://rubygems.org/gems/binding_of_caller): `gem install binding_of_caller`
21
21
  * See the [source code](http://github.com/banister/binding_of_caller)
@@ -52,7 +52,7 @@ This project is a spinoff from the [Pry REPL project.](http://pry.github.com)
52
52
  Features and limitations
53
53
  -------------------------
54
54
 
55
- * Only works with MRI 1.9.2, 1.9.3 and RBX (Rubinius)
55
+ * Only works with MRI 1.9.2, 1.9.3, 2.0 and RBX (Rubinius)
56
56
  * Does not work in 1.8.7, but there is a well known (continuation-based) hack to get a `Binding#of_caller` there.
57
57
 
58
58
  Contact
@@ -66,7 +66,7 @@ License
66
66
 
67
67
  (The MIT License)
68
68
 
69
- Copyright (c) 2011 (John Mair)
69
+ Copyright (c) 2012 (John Mair)
70
70
 
71
71
  Permission is hereby granted, free of charge, to any person obtaining
72
72
  a copy of this software and associated documentation files (the
@@ -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.9"
5
+ s.version = "0.7.2"
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 = "2013-02-14"
9
+ s.date = "2013-06-07"
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
- 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/mri2.rb", "lib/binding_of_caller/rubinius.rb", "lib/binding_of_caller/version.rb", "test/test_binding_of_caller.rb"]
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/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/rubys_gc.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/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/rubys_gc.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/mri2.rb", "lib/binding_of_caller/rubinius.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 = "2.0.0.rc.2"
16
+ s.rubygems_version = "2.0.3"
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
 
@@ -2,7 +2,7 @@
2
2
 
3
3
  #include <ruby.h>
4
4
  #include "vm_core.h"
5
- #include "gc.h"
5
+ #include "rubys_gc.h"
6
6
 
7
7
  typedef enum { false, true } bool;
8
8
 
@@ -1,13 +1,5 @@
1
1
  #define RUBY_VERSION "1.9.2"
2
- <<<<<<< HEAD
3
- <<<<<<< HEAD
4
- #define RUBY_PATCHLEVEL 34
5
- =======
6
- #define RUBY_PATCHLEVEL 27
7
- >>>>>>> 7f5d559... merges r29155 from trunk into ruby_1_9_2. fixes #3777, #3772 and #3722.
8
- =======
9
2
  #define RUBY_PATCHLEVEL 30
10
- >>>>>>> 13fdd22... merges r29188 from trunk into ruby_1_9_2.
11
3
  #define RUBY_VERSION_MAJOR 1
12
4
  #define RUBY_VERSION_MINOR 9
13
5
  #define RUBY_VERSION_TEENY 1
@@ -23,15 +23,15 @@ module BindingOfCaller
23
23
  loop do
24
24
  begin
25
25
  b = i.frame_binding(n)
26
-
27
- if b
28
- iseq = i.frame_iseq(n)
29
- b.instance_variable_set(:@iseq, iseq)
30
- ary << b
31
- end
32
26
  rescue ArgumentError
33
27
  break
34
28
  end
29
+
30
+ if b
31
+ b.instance_variable_set(:@iseq, i.frame_iseq(n))
32
+ ary << b
33
+ end
34
+
35
35
  n += 1
36
36
  end
37
37
  end
@@ -6,19 +6,20 @@ module BindingOfCaller
6
6
  def of_caller(n)
7
7
  bt = Rubinius::VM.backtrace(1 + n, true).first
8
8
 
9
+ raise RuntimeError, "Invalid frame, gone beyond end of stack!" if bt.nil?
10
+
9
11
  b = Binding.setup(
10
12
  bt.variables,
11
13
  bt.variables.method,
12
- bt.static_scope,
14
+ bt.constant_scope,
13
15
  bt.variables.self,
14
16
  bt
15
17
  )
16
18
 
17
- b.instance_variable_set(:@frame_description, bt.describe)
19
+ b.instance_variable_set :@frame_description,
20
+ bt.describe.gsub("{ } in", "block in")
18
21
 
19
22
  b
20
- rescue
21
- raise RuntimeError, "Invalid frame, gone beyond end of stack!"
22
23
  end
23
24
 
24
25
  # The description of the frame.
@@ -54,20 +55,16 @@ module BindingOfCaller
54
55
  # The type of the frame.
55
56
  # @return [Symbol]
56
57
  def frame_type
57
- case self.variables.method.metadata.to_a.first.to_s
58
- when /block/
59
- :block
60
- when /eval/
58
+ if compiled_code.for_module_body?
59
+ :class
60
+ elsif compiled_code.for_eval?
61
61
  :eval
62
+ elsif compiled_code.is_block?
63
+ :block
62
64
  else
63
- if frame_description =~ /__(?:class|module)_init__/
64
- :class
65
- else
66
- :method
67
- end
65
+ :method
68
66
  end
69
67
  end
70
-
71
68
  end
72
69
  end
73
70
 
@@ -1,3 +1,3 @@
1
1
  module BindingOfCaller
2
- VERSION = "0.7.1"
2
+ VERSION = "0.7.2"
3
3
  end
@@ -84,12 +84,12 @@ describe BindingOfCaller do
84
84
  binding.frame_count.should == binding.callers.count
85
85
  end
86
86
  end
87
-
87
+
88
88
  describe "frame_descripton" do
89
89
  it 'can be called on ordinary binding without raising' do
90
90
  lambda { binding.frame_description }.should.not.raise
91
91
  end
92
-
92
+
93
93
  it 'describes a block frame' do
94
94
  binding.of_caller(0).frame_description.should =~ /block/
95
95
  end
@@ -104,7 +104,7 @@ describe BindingOfCaller do
104
104
 
105
105
  it 'describes a class frame' do
106
106
  class HorseyMalone
107
- binding.of_caller(0).frame_description.should =~ /class/
107
+ binding.of_caller(0).frame_description.should =~ /class/i
108
108
  end
109
109
  Object.remove_const(:HorseyMalone)
110
110
  end
@@ -114,36 +114,48 @@ describe BindingOfCaller do
114
114
  it 'can be called on ordinary binding without raising' do
115
115
  lambda { binding.frame_type }.should.not.raise
116
116
  end
117
-
118
- it 'should return the correct frame types' do
119
- o = Object.new
120
117
 
121
- # method frame
122
- def o.a
123
- b
118
+ describe "when inside a class definition" do
119
+ before do
120
+ class HorseyMalone
121
+ @binding = binding.of_caller(0)
122
+ def self.binding; @binding; end
123
+ end
124
+ @binding = HorseyMalone.binding
124
125
  end
125
126
 
126
- # method frame
127
- def o.b
128
- # block frame
129
- proc do
130
- binding.callers
131
- end.call
127
+ it 'returns :class' do
128
+ @binding.frame_type.should == :class
132
129
  end
133
- caller_bindings = o.a
134
- caller_bindings[0].frame_type.should == :block
135
- caller_bindings[1].frame_type.should == :method
136
- caller_bindings[2].frame_type.should == :method
137
130
  end
138
131
 
139
- it 'identifies a class frame' do
140
- class HorseyMalone
141
- binding.of_caller(0).frame_type.should == :class
132
+ describe "when evaluated" do
133
+ before { @binding = eval("binding.of_caller(0)") }
134
+
135
+ it 'returns :eval' do
136
+ @binding.frame_type.should == :eval
142
137
  end
138
+ end
143
139
 
144
- Object.remove_const(:HorseyMalone)
140
+ describe "when inside a block" do
141
+ before { @binding = proc { binding.of_caller(0) }.call }
142
+
143
+ it 'returns :block' do
144
+ @binding.frame_type.should == :block
145
+ end
145
146
  end
146
147
 
148
+ describe "when inside an instance method" do
149
+ before do
150
+ o = Object.new
151
+ def o.a; binding.of_caller(0); end
152
+ @binding = o.a;
153
+ end
154
+
155
+ it 'returns :method' do
156
+ @binding.frame_type.should == :method
157
+ end
158
+ end
147
159
  end
148
160
  end
149
161
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: binding_of_caller
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.1
4
+ version: 0.7.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - John Mair (banisterfiend)
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-02-16 00:00:00.000000000 Z
11
+ date: 2013-06-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: debug_inspector
@@ -76,7 +76,6 @@ files:
76
76
  - ext/binding_of_caller/ruby_headers/192/debug.h
77
77
  - ext/binding_of_caller/ruby_headers/192/dln.h
78
78
  - ext/binding_of_caller/ruby_headers/192/eval_intern.h
79
- - ext/binding_of_caller/ruby_headers/192/gc.h
80
79
  - ext/binding_of_caller/ruby_headers/192/id.h
81
80
  - ext/binding_of_caller/ruby_headers/192/iseq.h
82
81
  - ext/binding_of_caller/ruby_headers/192/method.h
@@ -84,6 +83,7 @@ files:
84
83
  - ext/binding_of_caller/ruby_headers/192/regenc.h
85
84
  - ext/binding_of_caller/ruby_headers/192/regint.h
86
85
  - ext/binding_of_caller/ruby_headers/192/regparse.h
86
+ - ext/binding_of_caller/ruby_headers/192/rubys_gc.h
87
87
  - ext/binding_of_caller/ruby_headers/192/thread_pthread.h
88
88
  - ext/binding_of_caller/ruby_headers/192/thread_win32.h
89
89
  - ext/binding_of_caller/ruby_headers/192/timev.h
@@ -100,7 +100,6 @@ files:
100
100
  - ext/binding_of_caller/ruby_headers/193/dln.h
101
101
  - ext/binding_of_caller/ruby_headers/193/encdb.h
102
102
  - ext/binding_of_caller/ruby_headers/193/eval_intern.h
103
- - ext/binding_of_caller/ruby_headers/193/gc.h
104
103
  - ext/binding_of_caller/ruby_headers/193/id.h
105
104
  - ext/binding_of_caller/ruby_headers/193/internal.h
106
105
  - ext/binding_of_caller/ruby_headers/193/iseq.h
@@ -111,6 +110,7 @@ files:
111
110
  - ext/binding_of_caller/ruby_headers/193/regint.h
112
111
  - ext/binding_of_caller/ruby_headers/193/regparse.h
113
112
  - ext/binding_of_caller/ruby_headers/193/revision.h
113
+ - ext/binding_of_caller/ruby_headers/193/rubys_gc.h
114
114
  - ext/binding_of_caller/ruby_headers/193/thread_pthread.h
115
115
  - ext/binding_of_caller/ruby_headers/193/thread_win32.h
116
116
  - ext/binding_of_caller/ruby_headers/193/timev.h
@@ -145,7 +145,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
145
145
  version: '0'
146
146
  requirements: []
147
147
  rubyforge_project:
148
- rubygems_version: 2.0.0.rc.2
148
+ rubygems_version: 2.0.3
149
149
  signing_key:
150
150
  specification_version: 4
151
151
  summary: Retrieve the binding of a method's caller. Can also retrieve bindings even