The NetBeans TM Ruby IDE: You Thought Rails Development Was Fun Before Tor Norbye and Brian Leonard Sr. Software Engineers Sun Microsystems TS-5249
Learn how to jump-start your Ruby and Rails development using NetBeans software 2008 JavaOne SM Conference java.sun.com/javaone 2
Agenda Project Generation / Rails Generators Editing/Navigation Execution & Testing Debugging Rails + Java class library Deployment Futures 2008 JavaOne SM Conference java.sun.com/javaone 3
Project Creation / Rails Generators Start from scratch or work with existing sources Generate project artifacts Scaffolds Models Controllers Migrations Integration tests 2008 JavaOne SM Conference java.sun.com/javaone 4
Rails Project Creation 2008 JavaOne SM Conference java.sun.com/javaone 5
Agenda Project Generation / Rails Generators Editing/Navigation Execution & Testing Debugging Rails + Java class library Deployment Futures 2008 JavaOne SM Conference java.sun.com/javaone 6
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. 2008 JavaOne SM Conference java.sun.com/javaone 7
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 2008 JavaOne SM Conference java.sun.com/javaone 8
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 RDoc NetBeans 2008 JavaOne SM Conference java.sun.com/javaone 9
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 do/end blocks, etc. 2008 JavaOne SM Conference java.sun.com/javaone 10
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> 2008 JavaOne SM Conference java.sun.com/javaone 11
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 HAML (experimental) 2008 JavaOne SM Conference java.sun.com/javaone 12
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. 2008 JavaOne SM Conference java.sun.com/javaone 13
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 2008 JavaOne SM Conference java.sun.com/javaone 14
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 Open Type (Ctrl-O) 2008 JavaOne SM Conference java.sun.com/javaone 15
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) #*load* => all_loaders 2008 JavaOne SM Conference java.sun.com/javaone 16
Editing/Navigation 2008 JavaOne SM Conference java.sun.com/javaone 17
Agenda Project Generation / Rails Generators Editing/Navigation Execution & Testing Debugging Rails + Java class library Deployment Futures 2008 JavaOne SM Conference java.sun.com/javaone 18
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 summary results 2008 JavaOne SM Conference java.sun.com/javaone 19
Execution & Testing 2008 JavaOne SM Conference java.sun.com/javaone 20
Agenda Project Generation / Rails Generators Editing/Navigation Execution & Testing Debugging Rails + Java class library Deployment Futures 2008 JavaOne SM Conference java.sun.com/javaone 21
Source Level Debugging! Stepping Breakpoints Local Variables Call Stack Threads Watches Get it? Balloon-Evaluation 2008 JavaOne SM Conference java.sun.com/javaone 22
Debugging 2008 JavaOne SM Conference java.sun.com/javaone 23
Agenda Project Generation / Rails Generators Editing/Navigation Execution & Testing Debugging Rails + Java class library Deployment Futures 2008 JavaOne SM Conference java.sun.com/javaone 24
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 Set classpath to any 3 rd party Java class library 2008 JavaOne SM Conference java.sun.com/javaone 25
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 puts r.nextint 2008 JavaOne SM Conference java.sun.com/javaone 26
Java Integrated development 2008 JavaOne SM Conference java.sun.com/javaone 27
Agenda Project Generation / Rails Generators Editing/Navigation Execution & Testing Debugging Rails + Java class library Deployment Futures 2008 JavaOne SM Conference java.sun.com/javaone 28
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.) 2008 JavaOne SM Conference java.sun.com/javaone 29
Deployment to Java TM Servlet extension 2008 JavaOne SM Conference java.sun.com/javaone 30
Agenda Project Generation / Rails Generators Editing/Navigation Execution & Testing Debugging Rails + Java class library Deployment Futures 2008 JavaOne SM Conference java.sun.com/javaone 31
Future Plans Better console integration Better test runner GUI Improved type analysis More refactorings and Quickfixes Better Java integrated development Support for additional Ruby frameworks 2008 JavaOne SM Conference java.sun.com/javaone 32
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 2008 JavaOne SM Conference java.sun.com/javaone 33
For More Information LAB-8400 Developing (J)Ruby on Rails Applications with the NetBeans TM IDE http://wiki.netbeans.org/ruby users@ruby.netbeans.org http://blogs.sun.com/tor/ http://weblogs.java/net/blog/bleonard 2008 JavaOne SM Conference java.sun.com/javaone 34
Tor Norbye and Brian Leonard Sr. Software Engineers Sun Microsystems, Inc. TS-5249 2008 JavaOne SM Conference java.sun.com/javaone 35