Java Code Examples for org.jruby.Ruby#newInstance()
The following examples show how to use
org.jruby.Ruby#newInstance() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ModuleListTest.java From marathonv5 with Apache License 2.0 | 6 votes |
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()); }
Example 2
Source File: ModuleListTest.java From marathonv5 with Apache License 2.0 | 6 votes |
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()); }
Example 3
Source File: CommonContentAssistProcessor.java From APICloud-Studio with GNU General Public License v3.0 | 6 votes |
/** * 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; }
Example 4
Source File: ModuleListTest.java From marathonv5 with Apache License 2.0 | 5 votes |
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()); }
Example 5
Source File: ModuleListTest.java From marathonv5 with Apache License 2.0 | 5 votes |
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()); }
Example 6
Source File: RubyConsole.java From ramus with GNU General Public License v3.0 | 5 votes |
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; }
Example 7
Source File: JRubyRackInputTest.java From rack-servlet with Apache License 2.0 | 5 votes |
@Test public void shouldWrapJavaIOExceptions() throws Exception { Ruby ruby = Ruby.newInstance(); RackInput rackInput = mock(RackInput.class); when(rackInput.read(null)).thenThrow(new IOException("fake")); JRubyRackInput subject = new JRubyRackInput(ruby, rackInput); GlobalVariables globalVariables = ruby.getGlobalVariables(); globalVariables.set("$rack_input", subject); IRubyObject result = ruby.evalScriptlet( "begin; $rack_input.read; rescue IOError => e; \"rescued #{e.message}\"; end"); assertThat(result.asJavaString()).isEqualTo("rescued fake"); }
Example 8
Source File: ModuleListTest.java From marathonv5 with Apache License 2.0 | 4 votes |
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()); }