Package org.jruby

Examples of org.jruby.RubyRuntimeAdapter


            }
        };
    }

    public static RubyRuntimeAdapter newRuntimeAdapter() {
        return new RubyRuntimeAdapter() {
            public IRubyObject eval(Ruby runtime, String script) {
                return runtime.evalScriptlet(script);
            }
        };
    }
View Full Code Here


        RubyInstanceConfig config = new RubyInstanceConfig();
        config.processArguments(new String[]{"--debug"});
        Ruby rt = JavaEmbedUtils.initialize(Collections.emptyList(), config);
        NativeTracer tracer = new NativeTracer();
        rt.addEventHook(tracer);
        RubyRuntimeAdapter evaler = JavaEmbedUtils.newRuntimeAdapter();
        evaler.eval(rt, "sleep 0.01\nsleep 0.01\nsleep 0.01");
        assertEquals("expected tracing", Arrays.asList(1,1,1,2,2,2,3,3,3), tracer.lines);
    }
View Full Code Here

        }
    }

    public void testRubyExceptionWithoutCause() throws Exception {
        try {
            RubyRuntimeAdapter evaler = JavaEmbedUtils.newRuntimeAdapter();

            evaler.eval(runtime, "no_method_with_this_name");
            fail("Expected ScriptException");
        } catch (RaiseException re) {
            assertEquals("(NameError) undefined local variable or method `no_method_with_this_name' for main:Object", re.getMessage());
        }
    }
View Full Code Here

            }
        };
    }

    public static RubyRuntimeAdapter newRuntimeAdapter() {
        return new RubyRuntimeAdapter() {
            /**
             * Evaluate a script and return the last value in the script.
             * @param runtime to invoke the script under
             * @param script to be evaluated
             * @return the last value of the script
View Full Code Here

  private static final long serialVersionUID = -6048626637734368371L;

  @SuppressWarnings("unchecked")
  public TextReport<?> buildReport(Resource resource) throws Exception {
    Ruby runtime = JavaEmbedUtils.initialize(new ArrayList());
    RubyRuntimeAdapter evaler = JavaEmbedUtils.newRuntimeAdapter();

    String script = getContent(resource);
    IRubyObject eval = evaler.eval(runtime, script);

    TextReport textReport = (TextReport) JavaEmbedUtils.rubyToJava(runtime, eval, TextReport.class);

    if (textReport instanceof RbReport) {
      ((RbReport) textReport).setRuntime(runtime);
View Full Code Here

            }
        };
    }

    public static RubyRuntimeAdapter newRuntimeAdapter() {
        return new RubyRuntimeAdapter() {
            /**
             * Evaluate a script and return the last value in the script.
             * @param runtime to invoke the script under
             * @param script to be evaluated
             * @return the last value of the script
View Full Code Here

        context = new Mockery();
        runtime = JavaEmbedUtils.initialize(new LinkedList());
    }

    protected IRubyObject getConnectionUri(String uri) {
        final RubyRuntimeAdapter evaler = JavaEmbedUtils.newRuntimeAdapter();
        final IRubyObject result = evaler.eval(runtime, "require 'rubygems'\nrequire 'data_objects'\nDataObjects::URI.parse('" + uri + "')");
        assertEquals("DataObjects::URI", result.getType().getName());

        return result;
    }
View Full Code Here

        }
    }

    public void testRubyExceptionWithoutCause() throws Exception {
        try {
            RubyRuntimeAdapter evaler = JavaEmbedUtils.newRuntimeAdapter();

            evaler.eval(runtime, "no_method_with_this_name");
            fail("Expected ScriptException");
        } catch (RaiseException re) {
            assertEquals("(NameError) undefined local variable or method `no_method_with_this_name' for main:Object", re.getMessage());
        }
    }
View Full Code Here

            }
        };
    }

    public static RubyRuntimeAdapter newRuntimeAdapter() {
        return new RubyRuntimeAdapter() {
            /**
             * Evaluate a script and return the last value in the script.
             * @param runtime to invoke the script under
             * @param script to be evaluated
             * @return the last value of the script
View Full Code Here

TOP

Related Classes of org.jruby.RubyRuntimeAdapter

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.