Search in sources :

Example 46 with IRubyObject

use of org.jruby.runtime.builtin.IRubyObject in project gocd by gocd.

the class XmlDomParserContext method wrapDocument.

/**
 * This method is broken out so that HtmlDomParserContext can
 * override it.
 */
protected XmlDocument wrapDocument(ThreadContext context, RubyClass klazz, Document doc) {
    XmlDocument xmlDocument = (XmlDocument) NokogiriService.XML_DOCUMENT_ALLOCATOR.allocate(context.getRuntime(), klazz);
    xmlDocument.setDocumentNode(context, doc);
    xmlDocument.setEncoding(ruby_encoding);
    if (options.dtdLoad) {
        IRubyObject xmlDtdOrNil = XmlDtd.newFromExternalSubset(context.getRuntime(), doc);
        if (!xmlDtdOrNil.isNil()) {
            XmlDtd xmlDtd = (XmlDtd) xmlDtdOrNil;
            doc.setUserData(XmlDocument.DTD_EXTERNAL_SUBSET, xmlDtd, null);
        }
    }
    return xmlDocument;
}
Also used : XmlDtd(nokogiri.XmlDtd) XmlDocument(nokogiri.XmlDocument) IRubyObject(org.jruby.runtime.builtin.IRubyObject)

Example 47 with IRubyObject

use of org.jruby.runtime.builtin.IRubyObject in project cucumber-jvm by cucumber.

the class JRubyBackend method executeStepdef.

void executeStepdef(RubyObject stepdef, I18n i18n, Object[] args) {
    ArrayList<IRubyObject> jrubyArgs = new ArrayList<IRubyObject>();
    // jrubyWorld.@__gherkin_i18n = i18n
    RubyObject jrubyI18n = (RubyObject) JavaEmbedUtils.javaToRuby(stepdef.getRuntime(), i18n);
    currentWorld.callMethod("instance_variable_set", new IRubyObject[] { stepdef.getRuntime().newSymbol("@__gherkin_i18n"), jrubyI18n });
    jrubyArgs.add(currentWorld);
    for (Object o : args) {
        if (o == null) {
            jrubyArgs.add(null);
        } else if (o instanceof DataTable) {
            //Add a datatable as it stands...
            jrubyArgs.add(JavaEmbedUtils.javaToRuby(stepdef.getRuntime(), o));
        } else {
            jrubyArgs.add(stepdef.getRuntime().newString((String) o));
        }
    }
    stepdef.callMethod("execute", jrubyArgs.toArray(new IRubyObject[jrubyArgs.size()]));
}
Also used : DataTable(cucumber.api.DataTable) ArrayList(java.util.ArrayList) RubyObject(org.jruby.RubyObject) IRubyObject(org.jruby.runtime.builtin.IRubyObject) IRubyObject(org.jruby.runtime.builtin.IRubyObject) RubyObject(org.jruby.RubyObject) IRubyObject(org.jruby.runtime.builtin.IRubyObject)

Example 48 with IRubyObject

use of org.jruby.runtime.builtin.IRubyObject in project cucumber-jvm by cucumber.

the class JRubyStepDefinition method matchedArguments.

@Override
public List<Argument> matchedArguments(Step step) {
    RubyString stepName = stepdefRunner.getRuntime().newString(step.getName());
    IRubyObject arguments = stepdefRunner.callMethod("matched_arguments", stepName);
    return toJava(arguments);
}
Also used : RubyString(org.jruby.RubyString) IRubyObject(org.jruby.runtime.builtin.IRubyObject)

Example 49 with IRubyObject

use of org.jruby.runtime.builtin.IRubyObject in project enumerable by hraberg.

the class JRubyTest method interactingWithJavaScript.

@Test
public void interactingWithJavaScript() throws Exception {
    Ruby ruby = Ruby.getGlobalRuntime();
    ScriptEngine js = JavaScriptTest.getJavaScriptEngine();
    Function f = (Function) js.eval("var f = function(n, m) { return n * m; }; f;");
    RubyProc proc = toProc(LambdaJavaScript.toFn2(f));
    assertEquals(ruby.newFloat(6), proc.call(ruby.getThreadService().getCurrentContext(), new IRubyObject[] { ruby.newFixnum(2), ruby.newFixnum(3) }));
    rb.put("block", proc);
    assertEquals(120.0, rb.eval("[1, 2, 3, 4, 5].inject &block"));
}
Also used : Function(sun.org.mozilla.javascript.internal.Function) RubyProc(org.jruby.RubyProc) IRubyObject(org.jruby.runtime.builtin.IRubyObject) Ruby(org.jruby.Ruby) LambdaJRuby(org.enumerable.lambda.support.jruby.LambdaJRuby) ScriptEngine(javax.script.ScriptEngine) GroovyTest(org.enumerable.lambda.support.groovy.GroovyTest) ScalaTest(org.enumerable.lambda.support.scala.ScalaTest) Test(org.junit.Test) ClojureTest(org.enumerable.lambda.support.clojure.ClojureTest) JavaScriptTest(org.enumerable.lambda.support.javascript.JavaScriptTest)

Example 50 with IRubyObject

use of org.jruby.runtime.builtin.IRubyObject in project enumerable by hraberg.

the class JRubyTest method convertFnToRubyProcKeepsDefaultValues.

@Test
public void convertFnToRubyProcKeepsDefaultValues() throws ScriptException {
    Ruby ruby = Ruby.getGlobalRuntime();
    RubyProc proc = toProc(Lambda.λ(s = "world", s.toUpperCase()));
    assertEquals(ruby.newString("WORLD"), proc.call(ruby.getThreadService().getCurrentContext(), new IRubyObject[] {}));
}
Also used : RubyProc(org.jruby.RubyProc) IRubyObject(org.jruby.runtime.builtin.IRubyObject) Ruby(org.jruby.Ruby) LambdaJRuby(org.enumerable.lambda.support.jruby.LambdaJRuby) GroovyTest(org.enumerable.lambda.support.groovy.GroovyTest) ScalaTest(org.enumerable.lambda.support.scala.ScalaTest) Test(org.junit.Test) ClojureTest(org.enumerable.lambda.support.clojure.ClojureTest) JavaScriptTest(org.enumerable.lambda.support.javascript.JavaScriptTest)

Aggregations

IRubyObject (org.jruby.runtime.builtin.IRubyObject)105 JRubyMethod (org.jruby.anno.JRubyMethod)32 Document (org.w3c.dom.Document)27 Ruby (org.jruby.Ruby)25 Node (org.w3c.dom.Node)24 RubyString (org.jruby.RubyString)16 RubyArray (org.jruby.RubyArray)13 NokogiriHelpers.rubyStringToString (nokogiri.internals.NokogiriHelpers.rubyStringToString)11 RaiseException (org.jruby.exceptions.RaiseException)10 InputStream (java.io.InputStream)6 ClojureTest (org.enumerable.lambda.support.clojure.ClojureTest)6 GroovyTest (org.enumerable.lambda.support.groovy.GroovyTest)6 JavaScriptTest (org.enumerable.lambda.support.javascript.JavaScriptTest)6 LambdaJRuby (org.enumerable.lambda.support.jruby.LambdaJRuby)6 ScalaTest (org.enumerable.lambda.support.scala.ScalaTest)6 RubyProc (org.jruby.RubyProc)6 Test (org.junit.Test)6 ByteArrayInputStream (java.io.ByteArrayInputStream)5 IOException (java.io.IOException)4 NokogiriHelpers.clearCachedNode (nokogiri.internals.NokogiriHelpers.clearCachedNode)4