本文整理汇总了Java中org.jruby.Ruby.newInstance方法的典型用法代码示例。如果您正苦于以下问题:Java Ruby.newInstance方法的具体用法?Java Ruby.newInstance怎么用?Java Ruby.newInstance使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.jruby.Ruby
的用法示例。
在下文中一共展示了Ruby.newInstance方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: checkForWindowNameAndComments
import org.jruby.Ruby; //导入方法依赖的package包/类
public void checkForWindowNameAndComments() throws Exception {
ModuleList moduleList = new ModuleList(Ruby.newInstance(), "authentication");
Module top = moduleList.getTop();
List<Module> modules = top.getChildren();
assertEquals(1, modules.size());
Module login = modules.get(0);
assertEquals("login", login.getName());
List<Function> functions = login.getFunctions();
assertEquals(2, functions.size());
Function loginFunction = functions.get(0);
String lineSepearator = System.getProperty("line.separator");
assertEquals(
convert2code(new String[] { "=begin", "This is an example with with_window call and comments", "=end" }).trim(),
loginFunction.getDocumentation().trim().replaceAll("\n", lineSepearator));
assertEquals("Login", loginFunction.getWindow());
Function loginFunction2 = functions.get(1);
assertEquals("", loginFunction2.getDocumentation());
assertNull(loginFunction2.getWindow());
}
示例2: checkForListArgs
import org.jruby.Ruby; //导入方法依赖的package包/类
public void checkForListArgs() throws Exception {
ModuleList moduleList = new ModuleList(Ruby.newInstance(), "selection");
Module top = moduleList.getTop();
List<Module> modules = top.getChildren();
assertEquals(1, modules.size());
Module arrays = modules.get(0);
assertEquals("arrays", arrays.getName());
List<Function> functions = arrays.getFunctions();
assertEquals(3, functions.size());
Function selectOneFunction = functions.get(0);
assertEquals("select_one", selectOneFunction.getName());
List<Argument> arguments = selectOneFunction.getArguments();
assertEquals(2, arguments.size());
Argument arg = arguments.get(0);
assertEquals("integers", arg.getName());
assertNull(arg.getDefault());
assertNotNull(arg.getDefaultList());
arg = arguments.get(1);
assertEquals("strings", arg.getName());
assertNull(arg.getDefault(), arg.getDefault());
assertNotNull(arg.getDefaultList());
}
示例3: addRubleProposals
import org.jruby.Ruby; //导入方法依赖的package包/类
/**
* This hooks our Ruble scripting up to Content Assist, allowing them to contribute possible proposals. Experimental
* right now as the way to return results is... interesting.
*
* @param viewer
* @param offset
* @return
*/
protected List<ICompletionProposal> addRubleProposals(ITextViewer viewer, int offset)
{
ArrayList<ICompletionProposal> proposals = new ArrayList<ICompletionProposal>();
try
{
String scope = getDocumentScopeManager().getScopeAtOffset(viewer, offset);
List<ContentAssistElement> commands = getBundleManager().getContentAssists(new ScopeFilter(scope));
if (!CollectionsUtil.isEmpty(commands))
{
Ruby ruby = Ruby.newInstance();
for (ContentAssistElement ce : commands)
{
proposals.addAll(addRubleCAProposals(viewer, offset, ruby, ce));
}
}
}
catch (BadLocationException e)
{
IdeLog.logError(CommonEditorPlugin.getDefault(), e);
}
proposals.trimToSize();
return proposals;
}
示例4: returnsFunctionsFromAFile
import org.jruby.Ruby; //导入方法依赖的package包/类
public void returnsFunctionsFromAFile() throws Exception {
ModuleList moduleList = new ModuleList(Ruby.newInstance(), "moduledir");
Module top = moduleList.getTop();
assertEquals(1, top.getChildren().size());
assertEquals(0, top.getFunctions().size());
Module module = top.getChildren().get(0);
assertEquals(1, module.getFunctions().size());
assertEquals(0, module.getChildren().size());
Function f = module.getFunctions().get(0);
assertEquals("module_function_1", f.getName());
assertEquals("f", f.getArguments().get(0).getName());
assertEquals("s", f.getArguments().get(1).getName());
assertEquals(null, f.getArguments().get(0).getDefault());
assertEquals("Hello", f.getArguments().get(1).getDefault());
}
示例5: returnsFunctionsFromSubdirectories
import org.jruby.Ruby; //导入方法依赖的package包/类
public void returnsFunctionsFromSubdirectories() throws Exception {
ModuleList moduleList = new ModuleList(Ruby.newInstance(), "moduledir2");
Module top = moduleList.getTop();
assertEquals(2, top.getChildren().size());
Module subdir = top.getChildren().get(0);
assertEquals("subdir", subdir.getName());
Module subdir2 = top.getChildren().get(1);
assertEquals("subdir", subdir2.getName());
}
示例6: createComponent
import org.jruby.Ruby; //导入方法依赖的package包/类
public JComponent createComponent() {
JPanel panel = new JPanel();
JPanel console = new JPanel();
panel.setLayout(new BorderLayout());
final JEditorPane text = new JTextPane();
text.setMargin(new Insets(8, 8, 8, 8));
text.setCaretColor(new Color(0xa4, 0x00, 0x00));
text.setBackground(new Color(0xf2, 0xf2, 0xf2));
text.setForeground(new Color(0xa4, 0x00, 0x00));
Font font = findFont("Monospaced", Font.PLAIN, 14, new String[]{
"Monaco", "Andale Mono"});
text.setFont(font);
JScrollPane pane = new JScrollPane();
pane.setViewportView(text);
pane.setBorder(BorderFactory.createLineBorder(Color.darkGray));
panel.add(pane, BorderLayout.CENTER);
console.validate();
final TextAreaReadline tar = new TextAreaReadline(text,
getString("Wellcom") + " \n\n");
RubyInstanceConfig config = new RubyInstanceConfig() {
{
//setInput(tar.getInputStream());
//setOutput(new PrintStream(tar.getOutputStream()));
//setError(new PrintStream(tar.getOutputStream()));
setObjectSpaceEnabled(false);
}
};
Ruby runtime = Ruby.newInstance(config);
tar.hookIntoRuntimeWithStreams(runtime);
run(runtime);
return panel;
}
示例7: testCISCOPattern
import org.jruby.Ruby; //导入方法依赖的package包/类
@Test
public void testCISCOPattern() throws Exception {
// Adding configuration file
Path path = new Path(GrokIngestMapperTest.class.getClassLoader()
.getResource("grok" + File.separator + "CISCO.conf").getPath());
// Adding extra patterns file
Ruby runtime = Ruby.newInstance();
RubyArray rubyArray = RubyArray.newArray(runtime);
rubyArray.add(GrokIngestMapperTest.class.getClassLoader()
.getResource("grok" + File.separator + "extra_patterns.txt").getPath());
jobConf.set(GrokIngestMapper.GROK_URI, path.toString());
mapper.getFixture().init(jobConf);
mapDriver.withConfiguration(jobConf);
String splitFilePath = "/path/to/log";
mapDriver.setMapInputPath(new Path(splitFilePath));
LongWritable lineNumb = new LongWritable(10);
String message = "Mar 20 2014 20:10:45 key1=value1 key2=value2 key3=value3";
mapDriver.withInput(lineNumb, new Text(message));
List<Pair<Text, LWDocumentWritable>> run = mapDriver.run();
Assert.assertEquals(1, run.size());
Pair<Text, LWDocumentWritable> pair = run.get(0);
LWDocument doc = pair.getSecond().getLWDocument();
Assert.assertNotNull(doc);
// TODO: Check Fields
}
示例8: JRubyAdapter
import org.jruby.Ruby; //导入方法依赖的package包/类
/**
* Constructor.
*
* @throws LanguageAdapterException
* In case of an initialization error
*/
public JRubyAdapter() throws LanguageAdapterException
{
super( "JRuby", Constants.VERSION, "Ruby", Constants.RUBY_VERSION, Arrays.asList( "rb" ), "rb", Arrays.asList( "ruby", "rb", "jruby" ), "jruby" );
RubyInstanceConfig config = new RubyInstanceConfig();
config.setClassCache( getRubyClassCache() );
config.setCompileMode( CompileMode.OFF );
compilerRuntime = Ruby.newInstance( config );
}
示例9: newRuntime
import org.jruby.Ruby; //导入方法依赖的package包/类
@Override
public Ruby newRuntime() throws RaiseException {
setLoadPaths(runtimeConfig);
Ruby runtime = Ruby.getThreadLocalRuntime();
if (runtime == null) {
runtime = Ruby.newInstance(runtimeConfig);
}
initDriftRuntime(runtime);
return runtime;
}
示例10: moduleListReturnsEmptyArrayWhenNoModulesAreAvailable
import org.jruby.Ruby; //导入方法依赖的package包/类
public void moduleListReturnsEmptyArrayWhenNoModulesAreAvailable() throws Exception {
ModuleList moduleList = new ModuleList(Ruby.newInstance(), "emptymoduledir");
Module top = moduleList.getTop();
assertEquals(0, top.getChildren().size());
assertEquals(0, top.getFunctions().size());
}
示例11: testAdditionalPattern
import org.jruby.Ruby; //导入方法依赖的package包/类
@Ignore
@Test
public void testAdditionalPattern() throws Exception {
// Generate the HDFS hierarchy
FileSystem fs = FileSystem.getLocal(jobConf);
Path dir = new Path(fs.getWorkingDirectory(), "build");
Path sub = new Path(dir, "GHT");
Path tempDir = new Path(sub, "tmp-dir");
Path base = new Path(sub, "tmp-dir-2");
fs.mkdirs(tempDir);
// Copy extra patterns file to HDFS
Path dst = new Path(base, "extra_patterns.txt");
Path src = new Path(GrokIngestMapperTest.class.getClassLoader()
.getResource("grok" + File.separator + "extra_patterns.txt").getPath());
fs.copyFromLocalFile(src, dst);
// Adding configuration file
Path confPath = new Path(GrokIngestMapperTest.class.getClassLoader()
.getResource("grok" + File.separator + "customPattern.conf").toURI().getPath());
// Adding extra patterns file
Ruby runtime = Ruby.newInstance();
RubyArray rubyArray = RubyArray.newArray(runtime);
rubyArray.add(
base.toUri().getPath() + File.separator + "extra_patterns.txt");
GrokHelper.addPatternDirToDC(rubyArray, jobConf);
jobConf.set(GrokIngestMapper.GROK_URI, confPath.toString());
mapper.getFixture().init(jobConf);
mapDriver.withConfiguration(jobConf);
String splitFilePath = "/path/to/log";
mapDriver.setMapInputPath(new Path(splitFilePath));
LongWritable lineNumb = new LongWritable(10);
String message = "192.168.1.1 123456 rest of the message";
mapDriver.withInput(lineNumb, new Text(message));
List<Pair<Text, LWDocumentWritable>> run = mapDriver.run();
Assert.assertEquals(1, run.size());
Pair<Text, LWDocumentWritable> pair = run.get(0);
LWDocument doc = pair.getSecond().getLWDocument();
Assert.assertNotNull(doc);
// TODO: Check Fields
}
示例12: evalScriptlet
import org.jruby.Ruby; //导入方法依赖的package包/类
public static IRubyObject evalScriptlet(InputStream scriptStream) {
Ruby ruby = Ruby.newInstance();
Node scriptNode = ruby.parseFromMain(scriptStream, "test.rb");
return ruby.runInterpreter(scriptNode);
}