Sha256: f3876c87d0c63b7bd623e2b600542775e55762fb31cd8f5661f5a7b0ca631f0b

Contents?: true

Size: 1.66 KB

Versions: 3

Compression:

Stored size: 1.66 KB

Contents

package com.gsamokovarov.bindex;

import org.jruby.Ruby;
import org.jruby.RubyArray;
import org.jruby.RubyModule;
import org.jruby.RubyClass;
import org.jruby.runtime.ThreadContext;
import org.jruby.runtime.builtin.IRubyObject;
import org.jruby.runtime.builtin.InstanceVariables;
import org.jruby.anno.JRubyMethod;

public class JRubyIntegration {
    public static void setup(Ruby runtime) {
        RubyModule bindex = runtime.defineModule("Bindex");
        bindex.defineAnnotatedMethods(BindexMethods.class);

        RubyClass exception = runtime.getException();
        exception.defineAnnotatedMethods(ExceptionExtensionMethods.class);

        IRubyObject verbose = runtime.getVerbose();
        try {
            runtime.setVerbose(runtime.getNil());
            runtime.addEventHook(new SetExceptionBindingsEventHook());
        } finally {
            runtime.setVerbose(verbose);
        }
    }

    public static class BindexMethods {
        @JRubyMethod(name = "current_bindings", meta = true)
        public static IRubyObject currentBindings(ThreadContext context, IRubyObject self) {
            return RubyBindingsCollector.collectCurrentFor(context);
        }
    }

    public static class ExceptionExtensionMethods {
        @JRubyMethod
        public static IRubyObject bindings(ThreadContext context, IRubyObject self) {
            InstanceVariables instanceVariables = self.getInstanceVariables();

            IRubyObject bindings = instanceVariables.getInstanceVariable("@bindings");
            if (bindings != null && !bindings.isNil()) {
                return bindings;
            }

            return RubyArray.newArray(context.getRuntime());
        }
    }
}

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
bindex-0.5.0 ext/bindex/com/gsamokovarov/bindex/JRubyIntegration.java
bindex-0.4.0 ext/bindex/com/gsamokovarov/bindex/JRubyIntegration.java
bindex-0.3.0 ext/bindex/com/gsamokovarov/bindex/JRubyIntegration.java