CALL_RUBY

This activity "calls" a Ruby script.  Optionally, it can pass a list of argument values to the script.

For more information about Ruby, you might start by referring to Ruby Programming Language.

The implementation of the CALL_RUBY and CALL_RUBY_EX activities utilizes JRuby, which is an implementation of the Ruby Programming Language that runs in a Java Virtual Machine (JVM).  For more information about JRuby, we suggest you refer to Home – JRuby.org.  In order to use the CALL_RUBY or CALL_RUBY_EX activities, you must separately download and install JRuby-bin-1.7.10.zip from the http://jruby.org/ website.

The CALL_RUBY activity loads and evaluates the specified script.  Any Ruby code that is specified "globally" in the script (that is, outside of method and class definitions) will be executed.

For an alternative way to invoke code in a Ruby script, refer to the description of the CALL_RUBY_EX activity.

Note: This activity requires that the LANSA Integrator JSM is executing on a JVM at Java 6 or above.

 

CALL_RUBY Example

The following is an example of a Ruby script that receives two arguments, and treating them as strings, concatenates them and returns the result:

 

if ARGV.size < 2

    exit 1           # Error, incorrect number of arguments

end

 

operand1 = ARGV[0]

operand2 = ARGV[1]

result = operand1 + operand2

 

return result

 

 

A LANSA Composer Processing Sequence might invoke the script and receive the result in the following way:

 

INPUT Parameters:

SCRIPT: Required

This parameter must specify the path and filename of the Ruby script file to be loaded.  For example:

    C:\My_Ruby_Scripts\my_script.rb (for a Windows server), OR

    /My_Ruby_Scripts/my_script.rb (for an IBM i server)

ARGUMENTS: Optional

This parameter can specify a list of zero, one or more argument values that you wish to pass to the script.  The activity will pass one argument value for each value specified in the variable list provided in this parameter, in the order in which they are found in the variable list.

RUBYHOME: Optional

This parameter can specify the path to the JRuby home directory (where the JRuby executable files are located.  For example:

    C:\JRuby-1.7.10 (for a Windows server), OR

    /JRuby-1.7.10 (for an IBM i server)

(If not specified, or if the special value *DEFAULT is specified, then the CALL_RUBY activity will use the value specified in the LANSA Integrator rubyservice.properties file for the property name "rubyhome".)

LOADPATH: Optional

This parameter can specify the load path for additional Ruby script files.  If your Ruby script file specified in the SCRIPT parameter references other Ruby script files (for example using Ruby "require" or "load" directives), then you may need to specify the load path in this parameter to enable JRuby to locate the script files.

The default value is *AUTOMATIC, which means that the CALL_RUBY activity will use the same directory containing the script file specified in the SCRIPT parameter.  If all your script files are contained in one directory, then this value will usually work for you.

INPUT and OUTPUT Parameters:

RESULTSTATUS: Optional

The value returned in this parameter depends on the behavior of the script.  If the script uses the "return" directive, then this parameter will contain a string representation of the return value, if possible.  If the script uses an "exit" directive (which specifies an integer exit value), then this parameter will contain the exit value.