binding_of_caller 0.5.0 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -13,7 +13,7 @@ call stack, not limited to just the immediate caller.
13
13
 
14
14
  **Recommended for use only in debugging situations. Do not use this in production apps.**
15
15
 
16
- **Only works in MRI Ruby 1.9.2**
16
+ **Only works in MRI Ruby 1.9.2 and 1.9.3**
17
17
 
18
18
  * Install the [gem](https://rubygems.org/gems/binding_of_caller): `gem install binding_of_caller`
19
19
  * See the [source code](http://github.com/banister/binding_of_caller)
@@ -50,8 +50,7 @@ This project is a spinoff from the [Pry REPL project.](http://pry.github.com)
50
50
  Features and limitations
51
51
  -------------------------
52
52
 
53
- * Only works with MRI 1.9.2
54
- * Broken in 1.9.3, support will hopefully be provided in the near future.
53
+ * Only works with MRI 1.9.2 and 1.9.3
55
54
  * Does not work in 1.8.7, but there is a well known (continuation-based) hack to get a `Binding#of_caller` there.
56
55
 
57
56
  Contact
@@ -93,6 +93,25 @@ static rb_control_frame_t * find_valid_frame(rb_control_frame_t * cfp, rb_contro
93
93
  return NULL;
94
94
  }
95
95
 
96
+ static VALUE
97
+ frametype_name(VALUE flag)
98
+ {
99
+ switch (flag & VM_FRAME_MAGIC_MASK) {
100
+ case VM_FRAME_MAGIC_METHOD: return string2sym("method");
101
+ case VM_FRAME_MAGIC_BLOCK: return string2sym("block");
102
+ case VM_FRAME_MAGIC_CLASS: return string2sym("class");
103
+ case VM_FRAME_MAGIC_TOP: return string2sym("top");
104
+ case VM_FRAME_MAGIC_FINISH: return string2sym("finish");
105
+ case VM_FRAME_MAGIC_CFUNC: return string2sym("cfunc");
106
+ case VM_FRAME_MAGIC_PROC: return string2sym("proc");
107
+ case VM_FRAME_MAGIC_IFUNC: return string2sym("ifunc");
108
+ case VM_FRAME_MAGIC_EVAL: return string2sym("eval");
109
+ case VM_FRAME_MAGIC_LAMBDA: return string2sym("lambda");
110
+ default:
111
+ rb_raise(rb_eRuntimeError, "Unknown frame type! got flag: %d", FIX2INT(flag));
112
+ }
113
+ }
114
+
96
115
  static VALUE binding_of_caller(VALUE self, VALUE rb_level)
97
116
  {
98
117
  rb_thread_t *th;
@@ -125,34 +144,22 @@ static VALUE binding_of_caller(VALUE self, VALUE rb_level)
125
144
  bind->filename = cfp->iseq->filename;
126
145
  bind->line_no = rb_vm_get_sourceline(cfp);
127
146
 
128
- rb_iv_set(bindval, "@frame_type", cfp->flag);
147
+ rb_iv_set(bindval, "@frame_type", frametype_name(cfp->flag));
148
+ rb_iv_set(bindval, "@frame_description", cfp->iseq->name);
149
+
129
150
  return bindval;
130
151
  }
131
152
 
132
-
133
153
  static VALUE
134
- frametype_name(VALUE flag)
154
+ frame_type(VALUE self)
135
155
  {
136
- switch (flag & VM_FRAME_MAGIC_MASK) {
137
- case VM_FRAME_MAGIC_METHOD: return string2sym("method");
138
- case VM_FRAME_MAGIC_BLOCK: return string2sym("block");
139
- case VM_FRAME_MAGIC_CLASS: return string2sym("class");
140
- case VM_FRAME_MAGIC_TOP: return string2sym("top");
141
- case VM_FRAME_MAGIC_FINISH: return string2sym("finish");
142
- case VM_FRAME_MAGIC_CFUNC: return string2sym("cfunc");
143
- case VM_FRAME_MAGIC_PROC: return string2sym("proc");
144
- case VM_FRAME_MAGIC_IFUNC: return string2sym("ifunc");
145
- case VM_FRAME_MAGIC_EVAL: return string2sym("eval");
146
- case VM_FRAME_MAGIC_LAMBDA: return string2sym("lambda");
147
- default:
148
- rb_raise(rb_eRuntimeError, "frame_type can only be returned for bindings created with Binding#of_caller().");
149
- }
156
+ return rb_iv_get(self, "@frame_type");
150
157
  }
151
158
 
152
159
  static VALUE
153
- frame_type(VALUE self)
160
+ frame_description(VALUE self)
154
161
  {
155
- return frametype_name(rb_iv_get(self, "@frame_type"));
162
+ return rb_iv_get(self, "@frame_description");
156
163
  }
157
164
 
158
165
  static VALUE frame_count(VALUE self)
@@ -199,6 +206,7 @@ Init_binding_of_caller()
199
206
  rb_define_method(mBindingOfCaller, "of_caller", binding_of_caller, 1);
200
207
  rb_define_method(mBindingOfCaller, "frame_count", frame_count, 0);
201
208
  rb_define_method(mBindingOfCaller, "frame_type", frame_type, 0);
209
+ rb_define_method(mBindingOfCaller, "frame_description", frame_description, 0);
202
210
  rb_define_method(mBindingOfCaller, "callers", callers, 0);
203
211
  rb_include_module(rb_cBinding, mBindingOfCaller);
204
212
  }
@@ -1,3 +1,3 @@
1
1
  module BindingOfCaller
2
- VERSION = "0.5.0"
2
+ VERSION = "0.6.0"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: binding_of_caller
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.6.0
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: 2011-11-05 00:00:00.000000000 Z
12
+ date: 2011-11-28 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bacon
16
- requirement: &70308421840640 !ruby/object:Gem::Requirement
16
+ requirement: &70166101101640 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
@@ -21,7 +21,7 @@ dependencies:
21
21
  version: 1.1.0
22
22
  type: :development
23
23
  prerelease: false
24
- version_requirements: *70308421840640
24
+ version_requirements: *70166101101640
25
25
  description: Retrieve the binding of a method's caller. Can also retrieve bindings
26
26
  even further up the stack. Currently only works for MRI 1.9.2.
27
27
  email: jrmair@gmail.com
@@ -110,7 +110,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
110
110
  version: '0'
111
111
  requirements: []
112
112
  rubyforge_project:
113
- rubygems_version: 1.8.11
113
+ rubygems_version: 1.8.10
114
114
  signing_key:
115
115
  specification_version: 3
116
116
  summary: Retrieve the binding of a method's caller. Can also retrieve bindings even