• No results found

The NetBeans TM Ruby IDE: You Thought Rails Development Was Fun Before

N/A
N/A
Protected

Academic year: 2021

Share "The NetBeans TM Ruby IDE: You Thought Rails Development Was Fun Before"

Copied!
35
0
0

Loading.... (view fulltext now)

Full text

(1)

The NetBeans

TM

Ruby IDE: You Thought

Rails Development Was Fun Before

Tor Norbye and Brian Leonard Sr. Software Engineers

Sun Microsystems

(2)

Learn how to jump-start your Ruby and Rails

development using NetBeans™ software

(3)

Agenda

Project Generation / Rails Generators

Editing/Navigation Execution & Testing Debugging

Rails + Java™ class library Deployment

(4)

Project Creation / Rails Generators

Start from scratch or work with existing sources Generate project artifacts

• Scaffolds

• Models

• Controllers

• Migrations

(5)
(6)

Agenda

Project Generation / Rails Generators

Editing/Navigation

Execution & Testing Debugging

Rails + Java class library Deployment

(7)

Editing: Code Completion

Code Completion for all the Rails APIs

...and any custom Ruby Gems you've installed ...and your own modules, classes and methods Parameter completion!

• On database table parameters in ActiveRecord calls

• Hash key completion: Known symbols like :order, :group and so on

for the various methods that take options hashes

• Hash value completion: When the hash key is something like

:controller, lists the available controller names; when the hash key is a boolean, lists :true and :false, and so on.

(8)

Editing: Active Record Code Completion

NetBeans software studies your database migrations files If present, it also studies your schema dump file

It builds up a logical model of your database models

Code completion for your model classes will include the dynamic database properties

Code completion will also include the dynamically added finder methods

(9)

Editing: Enhanced Documentation

Custom RDoc rendering recognizes code samples and syntax highlights them – not just for Ruby but for ERb as well

RDoc handling supports reformatting comments as well Ctrl-Space to show the comment you're editing as RDoc

(10)

Rails Quickfixes

Quickfixes are integrated with the tasklist

• Open the tasklist to scan all files in your projects for problems

Rails Deprecations Check

• Finds references to deprecated Rails functions and describes the

suggested change

• Detects usages of fields when you should be using the attribute

Actions without Views

• In controller files, it checks whether a method corresponds to a

view, and if not, adds a quickfix to create a view for the method

Ruby Quickfixes

• Detection of many common programming mistakes, deprecation

checks for APIS outside of Rails, and various code transformations such as reversing double negatives, converting between {} and

(11)

ERb Editing

ERb files are also known as RHTML files – the JavaServer Pages™ (JSP™) technology of the Ruby world, with Ruby embedded inside <% %> tags

All the Ruby editing features work in the Ruby scriptlets too

Spell checking of your HTML (user visible) text

Formatting, including compound indentation<h1>Header</h1>

<div>

<%# This line was indented by the <div> block %>

<span>HTML here</span> <% if true %>

<span>HTML indented further by Ruby</span>

<% end %>

<span>More HTML here</span> </div>

(12)

ERb Editing: Other Languages

Support for multiple embedded languages in your ERb:

• JavaScript™ programming language editing, CSS, HTML

JavaScript programming language editing includes most of the same features we have for Ruby – formatting, code

completion, go to declaration, quickfixes, ... YAML file editing

(13)

Editing: Type Analysis

If NetBeans software IDE knows the types of your

parameters, code completion etc. can be more accurate within the method

If NetBeans software IDE knows the return types from your methods, it can do a better job with expressions calling your method

Use Type Hints in your documentation to help the IDE

• #:arg:parameterName=>type

• #:return:=>type

The type information is also used for other IDE features, such as Go To Declaration.

(14)

Code Sample: Type Hints

#

# Creates an +n+ by +n+ identity matrix. # Matrix.identity(2) # => 1 0 # 0 1 # #:arg:n=>Fixnum #:return:=>Matrix def Matrix.identity(n) Matrix.scalar(n, 1) end

(15)

Navigation

Go To Declaration: Ctrl-click on classes, methods, fields and variables to jump to its declaration (Ctrl-B)

• Also works for references in documentation

• Knows about Rails-style references like :partial =>, :controller=>

and :action=> and takes those into account

• Ctrl-hover over symbols to read its documentation without jumping

Jump between a file and its test (Ctrl-Shift-T)

• Knows about Rails, Rspec, ZenTest and Test::Unit conventions

• If filename based search fails, finds tests by class names

regardless of where they are located

Jump between a Controller and its View (Ctrl-Shift-A)

• Figures out which view to jump to in a controller based on the caret

offset and parse information for the surrounding code

(16)

Navigation: Open Type

Jump to class

Jump to methods by prefixing with “#”. Various search styles are available.

• Prefix: actionc => ActionController::Base

• Regular Expression: *Cach*r => ActionCacheFilter

• CamelCase (AC::B => ActionController::Base)

• #to_s (all methods named to_s across all the classes)

(17)
(18)

Agenda

Project Generation / Rails Generators Editing/Navigation

Execution & Testing

Debugging

Rails + Java class library Deployment

(19)

Execution and Testing

Run File (Shift-F6). Performs context sensitive action for the current file

• For a controller or view or helper, fronts the browser and

shows/reloads the URL corresponding to the given controller or view (starting the Rails server if necessary)

• For a test, runs the test

• For an RSpec file, runs the file under RSpec's runner

• For migration files, runs rake migration to the migration file's level

• For Rakefiles, runs rake on the given rake file

• For other files, runs the file using Ruby

Test File (Ctrl-F6). Runs test for this file

• If this file is not a test/spec, finds the test for this file and runs that file instead

• Tests are run under test infrastructure, producing green/red

(20)
(21)

Agenda

Project Generation / Rails Generators Editing/Navigation

Execution & Testing

Debugging

Rails + Java class library Deployment

(22)

Source Level

Debugging

!

Stepping Breakpoints Local Variables Call Stack Threads Watches Balloon-Evaluation Get it?

(23)
(24)

Agenda

Project Generation / Rails Generators Editing/Navigation

Execution & Testing Debugging

Rails + Java class library

Deployment Futures

(25)

Java Integration

Load the high-level Java support (using 'include') Import classes (as with Java class library)

Use Java class library just like Ruby classes

(26)

Code Sample

# Load the high-level Java support

include Java

# Import the classes you want to use (Just as in Java)

import java.util.Random

# Create an instance of java.util.Random

r = Random.new

# Write a random integer to output

(27)
(28)

Agenda

Project Generation / Rails Generators Editing/Navigation

Execution & Testing Debugging

Rails + Java class library

Deployment

(29)

Deployment

WEBrick is bundled with JRuby

The popular Mongrel server is also supported

Goldspike plugin allows for deployment to Java Servlet extension (Tomcat, GlassFish, etc.)

(30)

Deployment to Java

TM

Servlet

(31)

Agenda

Project Generation / Rails Generators Editing/Navigation

Execution & Testing Debugging

Rails + Java class library Deployment

(32)

Future Plans

Better console integration Better test runner GUI

Improved type analysis

More refactorings and Quickfixes Better Java integrated development

(33)

Summary

NetBeans software IDE is a first class environment for Ruby and Rails development

Everything comes bundled to begin developing in Ruby immediately

With Ruby running on the Java VM (JRuby), Java integrated development is a snap

(34)

For More Information

LAB-8400 Developing (J)Ruby on Rails Applications with

the NetBeansTM IDE

http://wiki.netbeans.org/ruby [email protected] http://blogs.sun.com/tor/

(35)

Tor Norbye and Brian Leonard Sr. Software Engineers

Sun Microsystems, Inc. TS-5249

References

Related documents