Class RubyScript

java.lang.Object
org.tentackle.script.AbstractScript
org.tentackle.script.ruby.RubyScript
All Implemented Interfaces:
Script

public class RubyScript extends AbstractScript
A Ruby script.

The code is compiled lazily on first use into a CompiledRubyScript, shared by all scripts with the same code if cached. All scripts are executed by the single ScriptingContainer of the RubyLanguage, which is not thread-safe. Hence, if the script is thread-safe, execution is synchronized on the container. The variables are reset to nil after each execution.

Author:
harald
  • Constructor Details

    • RubyScript

      public RubyScript(RubyLanguage language, org.jruby.embed.ScriptingContainer container, String code, boolean cached, boolean threadSafe)
      Creates a Ruby script.
      Parameters:
      language - the language
      container - the scripting container
      code - the scripting code
      cached - true if cached
      threadSafe - true if thread-safety required
  • Method Details

    • validate

      public void validate()
    • execute

      public <T> T execute(Set<ScriptVariable> variables)
    • getCompiledScript

      protected CompiledRubyScript getCompiledScript()
      Gets the compiled script.
      Will be compiled if not done yet.
      Returns:
      the compiled script
    • compileScript

      protected CompiledRubyScript compileScript(String code)
      Compiles script code.
      Parameters:
      code - the scripting source code
      Returns:
      the compiled script
      Throws:
      ScriptRuntimeException - if compilation failed
    • executeImpl

      protected <T> T executeImpl(CompiledRubyScript script, Collection<ScriptVariable> variables)
      Executes the compiled script.
      The variables are bound to the container as instance variables and reset to nil after execution, so that subsequent scripts don't see their values and the objects can be garbage collected (as soon as the next script injects the nil).
      Type Parameters:
      T - the result type
      Parameters:
      script - the compiled script
      variables - the variables, null if none
      Returns:
      the result converted to Java, null if none