bindex 0.1.1 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +15 -1
- data/ext/bindex/com/gsamokovarov/bindex/JRubyIntegration.java +49 -0
- data/ext/bindex/cruby.c +13 -1
- data/ext/bindex/extconf.rb +1 -0
- data/lib/bindex/jruby.rb +2 -12
- data/lib/bindex/jruby_internals.jar +0 -0
- data/lib/bindex/jruby_internals_9k.jar +0 -0
- data/lib/bindex/rubinius.rb +19 -19
- data/lib/bindex/version.rb +1 -1
- data/test/current_bindings_test.rb +7 -0
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 34aa50088ea6aef2477158e8e8cc6e9c79bc61a9
|
4
|
+
data.tar.gz: f28ceecbdfcb050ad460d5b98ce1c49a3b471ae2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 26de5ac63dd38eee300a749896c9eb24e3c2aa76a3f28264282e703fe7052217e4f0bc6c62a768ed85812b3afe1032a1bcc30a01a76fee7f0873f92b99edfe89
|
7
|
+
data.tar.gz: add6aec5daa85df64266f3632afb64cf38c098bab43dffa41311537de8ee7f24e400aa1b5c2aba772c8524d878d04dc93eca8f101ca3a0d98692dd40615bc6ab
|
data/README.md
CHANGED
@@ -5,11 +5,25 @@ where did the exception originated in. Bindex gives you the bindings as well.
|
|
5
5
|
This can help you introspect the state of the Ruby program when the exception
|
6
6
|
happened.
|
7
7
|
|
8
|
-
|
8
|
+
## Usage
|
9
9
|
|
10
10
|
**Do not** use this gem on production environments. The performance penalty isn't
|
11
11
|
worth it anywhere outside of development.
|
12
12
|
|
13
|
+
### API
|
14
|
+
|
15
|
+
Bindex defines the following API:
|
16
|
+
|
17
|
+
#### Exception#bindings
|
18
|
+
|
19
|
+
Returns all the bindings up to the one in which the exception originated in.
|
20
|
+
|
21
|
+
#### Bindex.current_bindings
|
22
|
+
|
23
|
+
Returns all of the current Ruby execution state bindings. The first on is the
|
24
|
+
current one, the second is the caller one, the third is the caller of the
|
25
|
+
caller one and so on.
|
26
|
+
|
13
27
|
## Support
|
14
28
|
|
15
29
|
### CRuby
|
@@ -0,0 +1,49 @@
|
|
1
|
+
package com.gsamokovarov.bindex;
|
2
|
+
|
3
|
+
import org.jruby.Ruby;
|
4
|
+
import org.jruby.RubyArray;
|
5
|
+
import org.jruby.RubyModule;
|
6
|
+
import org.jruby.RubyClass;
|
7
|
+
import org.jruby.runtime.ThreadContext;
|
8
|
+
import org.jruby.runtime.builtin.IRubyObject;
|
9
|
+
import org.jruby.runtime.builtin.InstanceVariables;
|
10
|
+
import org.jruby.anno.JRubyMethod;
|
11
|
+
|
12
|
+
public class JRubyIntegration {
|
13
|
+
public static void setup(Ruby runtime) {
|
14
|
+
RubyModule bindex = runtime.defineModule("Bindex");
|
15
|
+
bindex.defineAnnotatedMethods(BindexMethods.class);
|
16
|
+
|
17
|
+
RubyClass exception = runtime.getException();
|
18
|
+
exception.defineAnnotatedMethods(ExceptionExtensionMethods.class);
|
19
|
+
|
20
|
+
IRubyObject verbose = runtime.getVerbose();
|
21
|
+
try {
|
22
|
+
runtime.setVerbose(runtime.getNil());
|
23
|
+
runtime.addEventHook(new SetExceptionBindingsEventHook());
|
24
|
+
} finally {
|
25
|
+
runtime.setVerbose(verbose);
|
26
|
+
}
|
27
|
+
}
|
28
|
+
|
29
|
+
private static class BindexMethods {
|
30
|
+
@JRubyMethod(name = "current_bindings", meta = true)
|
31
|
+
public static IRubyObject currentBindings(ThreadContext context, IRubyObject self) {
|
32
|
+
return RubyBindingsCollector.collectCurrentFor(context);
|
33
|
+
}
|
34
|
+
}
|
35
|
+
|
36
|
+
private static class ExceptionExtensionMethods {
|
37
|
+
@JRubyMethod
|
38
|
+
public static IRubyObject bindings(ThreadContext context, IRubyObject self) {
|
39
|
+
InstanceVariables instanceVariables = self.getInstanceVariables();
|
40
|
+
|
41
|
+
IRubyObject bindings = instanceVariables.getInstanceVariable("@bindings");
|
42
|
+
if (bindings != null && !bindings.isNil()) {
|
43
|
+
return bindings;
|
44
|
+
}
|
45
|
+
|
46
|
+
return RubyArray.newArray(context.getRuntime());
|
47
|
+
}
|
48
|
+
}
|
49
|
+
}
|
data/ext/bindex/cruby.c
CHANGED
@@ -1,5 +1,13 @@
|
|
1
1
|
#include "bindex.h"
|
2
2
|
|
3
|
+
VALUE bx_mBindex;
|
4
|
+
|
5
|
+
static VALUE
|
6
|
+
bx_current_bindings(VALUE self)
|
7
|
+
{
|
8
|
+
return current_bindings();
|
9
|
+
}
|
10
|
+
|
3
11
|
static VALUE
|
4
12
|
bx_exc_set_backtrace(VALUE self, VALUE bt)
|
5
13
|
{
|
@@ -14,7 +22,7 @@ bx_exc_set_backtrace(VALUE self, VALUE bt)
|
|
14
22
|
}
|
15
23
|
|
16
24
|
static VALUE
|
17
|
-
bx_exc_bindings(VALUE self
|
25
|
+
bx_exc_bindings(VALUE self)
|
18
26
|
{
|
19
27
|
VALUE bindings;
|
20
28
|
|
@@ -29,6 +37,10 @@ bx_exc_bindings(VALUE self, VALUE bt)
|
|
29
37
|
void
|
30
38
|
Init_cruby(void)
|
31
39
|
{
|
40
|
+
bx_mBindex = rb_define_module("Bindex");
|
41
|
+
|
42
|
+
rb_define_singleton_method(bx_mBindex, "current_bindings", bx_current_bindings, 0);
|
43
|
+
|
32
44
|
rb_define_method(rb_eException, "set_backtrace", bx_exc_set_backtrace, 1);
|
33
45
|
rb_define_method(rb_eException, "bindings", bx_exc_bindings, 0);
|
34
46
|
}
|
data/ext/bindex/extconf.rb
CHANGED
data/lib/bindex/jruby.rb
CHANGED
@@ -4,17 +4,7 @@ else
|
|
4
4
|
require 'bindex/jruby_internals'
|
5
5
|
end
|
6
6
|
|
7
|
+
java_import com.gsamokovarov.bindex.JRubyIntegration
|
7
8
|
java_import com.gsamokovarov.bindex.SetExceptionBindingsEventHook
|
8
9
|
|
9
|
-
|
10
|
-
previous_verbose, $VERBOSE = $VERBOSE, nil
|
11
|
-
JRuby.runtime.add_event_hook(SetExceptionBindingsEventHook.new)
|
12
|
-
ensure
|
13
|
-
$VERBOSE = previous_verbose
|
14
|
-
end
|
15
|
-
|
16
|
-
::Exception.class_eval do
|
17
|
-
def bindings
|
18
|
-
@bindings || []
|
19
|
-
end
|
20
|
-
end
|
10
|
+
JRubyIntegration.setup(JRuby.runtime)
|
Binary file
|
Binary file
|
data/lib/bindex/rubinius.rb
CHANGED
@@ -1,22 +1,5 @@
|
|
1
1
|
module Bindex
|
2
|
-
|
3
|
-
# Gets the current bindings for all available Ruby frames.
|
4
|
-
#
|
5
|
-
# Filters the internal Rubinius frames.
|
6
|
-
def self.current_bindings
|
7
|
-
locations = ::Rubinius::VM.backtrace(1, true)
|
8
|
-
|
9
|
-
InternalLocationFilter.new(locations).filter.map do |location|
|
10
|
-
Binding.setup(
|
11
|
-
location.variables,
|
12
|
-
location.variables.method,
|
13
|
-
location.constant_scope,
|
14
|
-
location.variables.self,
|
15
|
-
location
|
16
|
-
)
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
2
|
+
module Rubinius
|
20
3
|
# Filters internal Rubinius locations.
|
21
4
|
#
|
22
5
|
# There are a couple of reasons why we wanna filter out the locations.
|
@@ -47,6 +30,23 @@ module Bindex
|
|
47
30
|
end
|
48
31
|
end
|
49
32
|
|
33
|
+
# Gets the current bindings for all available Ruby frames.
|
34
|
+
#
|
35
|
+
# Filters the internal Rubinius and Bindex frames.
|
36
|
+
def Bindex.current_bindings
|
37
|
+
locations = ::Rubinius::VM.backtrace(1, true)
|
38
|
+
|
39
|
+
Bindex::Rubinius::InternalLocationFilter.new(locations).filter.map do |location|
|
40
|
+
Binding.setup(
|
41
|
+
location.variables,
|
42
|
+
location.variables.method,
|
43
|
+
location.constant_scope,
|
44
|
+
location.variables.self,
|
45
|
+
location
|
46
|
+
)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
50
|
::Exception.class_eval do
|
51
51
|
def bindings
|
52
52
|
@bindings || []
|
@@ -58,7 +58,7 @@ end
|
|
58
58
|
|
59
59
|
define_method(:raise_exception) do |exc|
|
60
60
|
if exc.bindings.empty?
|
61
|
-
exc.instance_variable_set(:@bindings, Bindex
|
61
|
+
exc.instance_variable_set(:@bindings, Bindex.current_bindings)
|
62
62
|
end
|
63
63
|
|
64
64
|
raise_exception.bind(self).call(exc)
|
data/lib/bindex/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bindex
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Genadi Samokovarov
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-12-
|
11
|
+
date: 2014-12-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: minitest
|
@@ -86,6 +86,7 @@ files:
|
|
86
86
|
- ext/bindex/bindings.c
|
87
87
|
- ext/bindex/com/gsamokovarov/bindex/BindingBuilder.java.erb
|
88
88
|
- ext/bindex/com/gsamokovarov/bindex/CurrentBindingsIterator.java
|
89
|
+
- ext/bindex/com/gsamokovarov/bindex/JRubyIntegration.java
|
89
90
|
- ext/bindex/com/gsamokovarov/bindex/RubyBindingsCollector.java
|
90
91
|
- ext/bindex/com/gsamokovarov/bindex/SetExceptionBindingsEventHook.java
|
91
92
|
- ext/bindex/com/gsamokovarov/bindex/ThreadContextInterfaceException.java
|
@@ -231,6 +232,7 @@ files:
|
|
231
232
|
- lib/bindex/jruby_internals_9k.jar
|
232
233
|
- lib/bindex/rubinius.rb
|
233
234
|
- lib/bindex/version.rb
|
235
|
+
- test/current_bindings_test.rb
|
234
236
|
- test/exception_test.rb
|
235
237
|
- test/fixtures/basic_nested_fixture.rb
|
236
238
|
- test/fixtures/custom_error_fixture.rb
|
@@ -263,6 +265,7 @@ signing_key:
|
|
263
265
|
specification_version: 4
|
264
266
|
summary: Bindings for your Ruby exceptions
|
265
267
|
test_files:
|
268
|
+
- test/current_bindings_test.rb
|
266
269
|
- test/exception_test.rb
|
267
270
|
- test/fixtures/basic_nested_fixture.rb
|
268
271
|
- test/fixtures/custom_error_fixture.rb
|