Sha256: 97fa1f86120b38f95cc2377492b80cbcf6f1dcf881ec1d8260f75bf554b898b2

Contents?: true

Size: 981 Bytes

Versions: 2

Compression:

Stored size: 981 Bytes

Contents

package org.pryrepl;

import org.jruby.runtime.builtin.IRubyObject;
import org.jruby.runtime.EventHook;
import org.jruby.runtime.RubyEvent;
import org.jruby.runtime.ThreadContext;
import org.jruby.RubyException;
import org.jruby.RubyBinding;
import org.jruby.RubyProc;

public class InterceptionEventHook extends EventHook {

    private RubyProc proc;

    public InterceptionEventHook(RubyProc proc) {
        super();
        this.proc = proc;
    }

    public boolean isInterestedInEvent(RubyEvent event) {
        return event.getName().equals(RubyEvent.RAISE.getName());
    }

    public void eventHandler(ThreadContext context, String eventName, String file, int line, String name, IRubyObject type) {
        RubyBinding binding = RubyBinding.newBinding(context.runtime, context.currentBinding());
        RubyException exception = (RubyException)context.runtime.getGlobalVariables().get("$!");
        proc.call(context, new IRubyObject[] {exception, binding});
    }
}

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
interception-0.1.pre.2 ext/org/pryrepl/InterceptionEventHook.java
interception-0.1.pre.1 ext/org/pryrepl/InterceptionEventHook.java