Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Rename to interception

  • Loading branch information...
commit 4947409d2c681b7f3646986919c2b76fa8b8c550 1 parent f7e6419
@ConradIrwin authored
View
4 ext/extconf.rb
@@ -3,14 +3,14 @@
if RbConfig::CONFIG['ruby_install_name'] == 'jruby'
File.open("Makefile", "w") do |f|
- f.write "install:\n\tjrubyc --javac org/pryrepl/RaiseAwarenessEventHook.java\n"
+ f.write "install:\n\tjrubyc --javac org/pryrepl/InterceptionEventHook.java\n"
end
elsif RbConfig::CONFIG['ruby_install_name'] == 'ruby'
require 'mkmf'
$CFLAGS += " -DRUBY_19" if RUBY_VERSION =~ /^1.9/
- extension_name = "raise_awareness"
+ extension_name = "interception"
dir_config(extension_name)
create_makefile(extension_name)
View
52 ext/interception.c
@@ -0,0 +1,52 @@
+#include "ruby.h"
+
+static VALUE rb_mInterception;
+
+#ifdef RUBY_19
+
+void
+interception_hook(rb_event_flag_t evflag, VALUE data, VALUE self, ID mid, VALUE klass)
+{
+ VALUE binding = rb_funcall(rb_mKernel, rb_intern("binding"), 0, NULL);
+ rb_funcall(rb_mInterception, rb_intern("rescue"), 2, rb_errinfo(), binding);
+}
+
+VALUE
+interception_start(VALUE self)
+{
+ rb_add_event_hook(interception_hook, RUBY_EVENT_RAISE, rb_mInterception);
+}
+
+#else
+
+#include "node.h"
+
+void
+interception_hook(rb_event_t event, NODE *node, VALUE self, ID mid, VALUE klass)
+{
+ VALUE binding = rb_funcall(rb_mKernel, rb_intern("binding"), 0, NULL);
+ rb_funcall(rb_mInterception, rb_intern("rescue"), 2, ruby_errinfo, binding);
+}
+
+VALUE
+interception_start(VALUE self)
+{
+ rb_add_event_hook(interception_hook, RUBY_EVENT_RAISE);
+}
+
+#endif
+
+VALUE
+interception_stop(VALUE self)
+{
+ rb_remove_event_hook(interception_hook);
+ return Qnil;
+}
+
+void
+Init_interception()
+{
+ rb_mInterception = rb_define_module("Interception");
+ rb_define_singleton_method(rb_mInterception, "start", interception_start, 0);
+ rb_define_singleton_method(rb_mInterception, "stop", interception_start, 0);
+}
View
4 ext/org/pryrepl/RaiseAwarenessEventHook.java → ext/org/pryrepl/InterceptionEventHook.java
@@ -8,11 +8,11 @@
import org.jruby.RubyBinding;
import org.jruby.RubyProc;
-public class RaiseAwarenessEventHook extends EventHook {
+public class InterceptionEventHook extends EventHook {
private RubyProc proc;
- public RaiseAwarenessEventHook(RubyProc proc) {
+ public InterceptionEventHook(RubyProc proc) {
super();
this.proc = proc;
}
View
52 ext/raise_awareness.c
@@ -1,52 +0,0 @@
-#include "ruby.h"
-
-static VALUE rb_mRaiseAwareness;
-
-#ifdef RUBY_19
-
-void
-raise_awareness_hook(rb_event_flag_t evflag, VALUE data, VALUE self, ID mid, VALUE klass)
-{
- VALUE binding = rb_funcall(rb_mKernel, rb_intern("binding"), 0, NULL);
- rb_funcall(rb_mRaiseAwareness, rb_intern("rescue"), 2, rb_errinfo(), binding);
-}
-
-VALUE
-raise_awareness_start(VALUE self)
-{
- rb_add_event_hook(raise_awareness_hook, RUBY_EVENT_RAISE, rb_mRaiseAwareness);
-}
-
-#else
-
-#include "node.h"
-
-void
-raise_awareness_hook(rb_event_t event, NODE *node, VALUE self, ID mid, VALUE klass)
-{
- VALUE binding = rb_funcall(rb_mKernel, rb_intern("binding"), 0, NULL);
- rb_funcall(rb_mRaiseAwareness, rb_intern("rescue"), 2, ruby_errinfo, binding);
-}
-
-VALUE
-raise_awareness_start(VALUE self)
-{
- rb_add_event_hook(raise_awareness_hook, RUBY_EVENT_RAISE);
-}
-
-#endif
-
-VALUE
-raise_awareness_stop(VALUE self)
-{
- rb_remove_event_hook(raise_awareness_hook);
- return Qnil;
-}
-
-void
-Init_raise_awareness()
-{
- rb_mRaiseAwareness = rb_define_module("RaiseAwareness");
- rb_define_singleton_method(rb_mRaiseAwareness, "start", raise_awareness_start, 0);
- rb_define_singleton_method(rb_mRaiseAwareness, "stop", raise_awareness_start, 0);
-}
View
6 raise_awareness.gemspec → interception.gemspec
@@ -1,10 +1,10 @@
Gem::Specification.new do |s|
- s.name = "raise_awareness"
+ s.name = "interception"
s.version = "0.1"
s.author = "Conrad Irwin"
s.email = "conrad.irwin@gmail.com"
- s.homepage = "http://github.com/ConradIrwin/raise_awareness"
- s.summary = "Easily intercept all exceptions when they happen."
+ s.homepage = "http://github.com/ConradIrwin/interception"
+ s.summary = "Intercept exceptions as they are being raised"
s.description = "Provides a cross-platform ability to intercept all exceptions as they are raised."
s.files = `git ls-files`.split("\n")
View
16 lib/raise_awareness.rb → lib/interception.rb
@@ -1,6 +1,6 @@
require 'thread'
-module RaiseAwareness
+module Interception
class << self
attr_accessor :mutex, :listeners
@@ -41,7 +41,7 @@ def self.rescue(e, binding)
if defined? Rubinius
def self.start
class << Rubinius
- alias raise_with_no_awareness raise_exception
+ alias raise_with_no_interception raise_exception
def raise_exception(exc)
bt = Rubinius::VM.backtrace(1, true).drop_while do |x|
@@ -49,20 +49,20 @@ def raise_exception(exc)
end.first
b = Binding.setup(bt.variables, bt.variables.method, bt.constant_scope, bt.variables.self, bt)
- RaiseAwareness.rescue(exc, b)
- raise_with_no_awareness(exc)
+ Interception.rescue(exc, b)
+ raise_with_no_interception(exc)
end
end
end
def self.stop
class << Rubinius
- alias raise_exception raise_with_no_awareness
+ alias raise_exception raise_with_no_interception
end
end
elsif defined?(JRuby)
$CLASSPATH << File.expand_path('../../ext/', __FILE__)
- java_import org.pryrepl.RaiseAwarenessEventHook
+ java_import org.pryrepl.InterceptionEventHook
def self.start
JRuby.runtime.add_event_hook(hook)
@@ -73,12 +73,12 @@ def self.stop
end
def self.hook
- @hook ||= RaiseAwarenessEventHook.new(proc do |e, b|
+ @hook ||= InterceptionEventHook.new(proc do |e, b|
self.rescue(e, b)
end)
end
else
- require File.expand_path('../../ext/raise_awareness.so', __FILE__)
+ require File.expand_path('../../ext/interception.so', __FILE__)
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.