Examples of runScriptlet()


Examples of org.jruby.embed.ScriptingContainer.runScriptlet()

        container.put(receiver, "@temp", "-5F");
        assertEquals("-5F", container.callMethod(receiver, "temp"));
        container.put(receiver, "SEASON", "colored leaves");
        container.put(receiver, "@@clouds", "thunder clouds");
        // need runScriptlet/callMethod to inject a new value
        container.runScriptlet("a=1");
        assertEquals("colored leaves", container.get(receiver, "SEASON"));
        assertEquals("thunder clouds", container.callMethod(receiver, "cloud_names"));
        assertEquals("thunder clouds", container.get(receiver, "@@clouds")); // this passes
        expResult.clear();
        expResult.add("cirrus"); expResult.add("stratus"); expResult.add("cumulus");
View Full Code Here

Examples of org.jruby.embed.ScriptingContainer.runScriptlet()

        assertEquals("tigers", container.get("$team"));
       
        container = new ScriptingContainer(LocalContextScope.SINGLETHREAD, LocalVariableBehavior.PERSISTENT);
        instance = container.getVarMap();
        container.put("trees", lvar_values);
        container.runScriptlet(script);
        klazz = container.get("Forecast");
        receiver = container.callMethod(klazz, "new", "blizzard", "6F");
        expResult.clear();
        expResult.add("cypress"); expResult.add("hemlock"); expResult.add("spruce");
        assertEquals(expResult, container.get("trees"));
View Full Code Here

Examples of org.jruby.embed.ScriptingContainer.runScriptlet()

        result = instance.getNames();
        assertEquals(expResult, result);
        assertTrue(result.size() == 5);
       
        // transient local variable should vanish after eval
        container.runScriptlet("a = 1");
        expResult = Arrays.asList("ARGV", "SEASON", "$sports", "@weather");
        result = instance.getNames();
        assertEquals(expResult, result);

        container = new ScriptingContainer(LocalContextScope.SINGLETHREAD, LocalVariableBehavior.GLOBAL);
View Full Code Here

Examples of org.jruby.embed.ScriptingContainer.runScriptlet()

        String[] weather = (String[]) container.remove("@weather");
        assertArrayEquals(expResult, weather);
        assertTrue(instance.size() == 4);
       
        // transient local variable should vanish after eval
        container.runScriptlet("a = 1");
        assertTrue(instance.size() == 3);
       
        container = new ScriptingContainer(LocalContextScope.SINGLETHREAD, LocalVariableBehavior.PERSISTENT);
        instance = container.getVarMap();
        container.put("ARGV", new String[] {"spring", "fall"});
View Full Code Here

Examples of org.jruby.embed.ScriptingContainer.runScriptlet()

            path[0] = path[0].replace(".class", "");//deletes the .class extension from the name
            path[1] = path[1].replaceFirst("/", "");//deletes first instance of "/" for Ruby code to work
        }try {
          ScriptingContainer container = new ScriptingContainer();
          container.setArgv(path);//sets ARGV
          container.runScriptlet(new BufferedReader(new FileReader("driver.rb")), "driver.rb");
    } catch (FileNotFoundException e) {
      System.out.println("No File chosen or file does not exist");
    } catch (NullPointerException npe)
    {
   
View Full Code Here

Examples of org.jruby.embed.ScriptingContainer.runScriptlet()

  public JRubyContainerAndReceiver jruby(String file) {
    ScriptingContainer container = new ScriptingContainer();
    String filename = "snippets/jruby/" + file + ".rb";
    return new JRubyContainerAndReceiver(container,
        container.runScriptlet(CodeLoader.class.getResourceAsStream("/" + filename), filename));
  }

  public ScriptEngine nashorn(String file) {
    try {
      ScriptEngine engine = new ScriptEngineManager().getEngineByName("nashorn");
View Full Code Here

Examples of org.jruby.embed.ScriptingContainer.runScriptlet()

    container.put("@claims", "");
    String script =
        "require \"jwt\"\n" +
        "@claims = JWT.decode(@token, \"secret\", \"HS256\").to_json\n" +
        "puts @claims";
    container.runScriptlet(script);
    assertEquals(TEST_CLAIMS, container.get("@claims"));
  }

  @Test
  public void canDecodeRubyHmacSignedToken() throws Exception {
View Full Code Here

Examples of org.jruby.embed.ScriptingContainer.runScriptlet()

    container.put("@token", "xxx");
    String script =
        "require \"jwt\"\n" +
        "@token = JWT.encode({\"some\" => \"payload\"}, \"secret\", \"HS256\")\n" +
        "puts @token";
    container.runScriptlet(script);
    String token = (String) container.get("@token");
    Jwt jwt = JwtHelper.decodeAndVerify(token, hmac);
    assertEquals(TEST_CLAIMS, jwt.getClaims());
    container.terminate();
  }
View Full Code Here

Examples of org.jruby.embed.ScriptingContainer.runScriptlet()

          String script =
              "require \"jwt\"\n" +
              "require \"bouncy-castle-java\"\n" +
              "require \"openssl\"";
          ScriptingContainer container = new ScriptingContainer();
          container.runScriptlet(script);
          setupOk = true;
        }
        catch (Exception e) {
          System.out.println("jruby.home not set or JWT gem not available. JWT ruby integration tests will be skipped" + e.getMessage());
        }
View Full Code Here

Examples of org.jruby.embed.ScriptingContainer.runScriptlet()

        result = instance.getNames();
        assertEquals(expResult, result);
        assertTrue(result.size() == 5);
       
        // transient local variable should vanish after eval
        container.runScriptlet("a = 1");
        expResult = Arrays.asList("ARGV", "SEASON", "$sports", "@weather");
        result = instance.getNames();
        assertEquals(expResult, result);

        container = new ScriptingContainer(LocalContextScope.SINGLETHREAD, LocalVariableBehavior.GLOBAL);
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.