From java to rails

1,156 views

Published on

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
1,156
On SlideShare
0
From Embeds
0
Number of Embeds
12
Actions
Shares
0
Downloads
7
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

From java to rails

  1. 1. From Java...to Rails Nick Sieger @nicksieger
  2. 2. Are you happy withyour development pace ?
  3. 3. ?How do you get to a place where it’s better?
  4. 4. IntroduceLanguage
  5. 5. Replace JSF with *Anything*
  6. 6. throw away
  7. 7. Built environment long-running projects with legacy codebases
  8. 8. Sagrada Família,Barcelona, Spain
  9. 9. passion facade nativity facadescaffolded interior
  10. 10. Ryugyong Hotel,2004 North Korea 2011
  11. 11. seismic retrofit
  12. 12. Szkieletor,Kraków, Poland
  13. 13. Metaphor Use Ruby, JRuby, and Rails to... Sagrada • Build new facade faster Familia • Scaffolding during refactoringRyugyong • Revive a project with a new face Hotel Seismic • Reinforce business rules with a DSL retrofit • Harden securitySzkieletor • Find novel uses for abandoned code
  14. 14. Metaphor Use Ruby, JRuby, and Rails to... Sagrada • Build new facade faster Familia • Scaffolding during refactoringRyugyong • Revive a project with a new face Hotel Seismic • Reinforce business rules with a DSL retrofit • Harden securitySzkieletor • Find novel uses for abandoned code
  15. 15. Metaphor Use Ruby, JRuby, and Rails to... Sagrada • Build new facade faster Familia • Scaffolding during refactoringRyugyong • Revive a project with a new face Hotel Seismic • Reinforce business rules with a DSL retrofit • Harden securitySzkieletor • Find novel uses for abandoned code
  16. 16. Metaphor Use Ruby, JRuby, and Rails to... Sagrada • Build new facade faster Familia • Scaffolding during refactoringRyugyong • Revive a project with a new face Hotel Seismic • Reinforce business rules with a DSL retrofit • Harden securitySzkieletor • Find novel uses for abandoned code
  17. 17. Metaphor Use Ruby, JRuby, and Rails to... Sagrada • Build new facade faster Familia • Scaffolding during refactoringRyugyong • Revive a project with a new face Hotel Seismic • Reinforce business rules with a DSL retrofit • Harden securitySzkieletor • Find novel uses for abandoned code
  18. 18. Biological evolution new replaces old over time
  19. 19. Strangler Fig
  20. 20. github.com/nicksieger/refactoring-to-rails
  21. 21. Before we begin...
  22. 22. Test PlanDon’t leave home without it
  23. 23. gembundler.com
  24. 24. Bundlersource :rubygemsgroup :test do gem rspec-rails gem cucumber-rails gem capybaraend
  25. 25. Feature: Owners Scenario: Add New Owner Given I am on the new owner page When I fill in the following: | First name | Dan | | Last name | Wood | | Address | 123 Main St | | City | Anywhere | | Telephone | 5555555 | And I press "Add Owner" Then I should see "Owner Information" within "h2" And I should see "Dan Wood"
  26. 26. Foot in the door Sneaking Ruby in
  27. 27. JRuby-Rackorg.jruby.rack:jruby-rack
  28. 28. ServletJava Ruby /* /rack/* App
  29. 29. <listener> <listener-class> org.jruby.rack.RackServletContextListener </listener-class></listener><servlet> <servlet-name>rack</servlet-name> <servlet-class>org.jruby.rack.RackServlet</servlet-class></servlet><servlet-mapping> <servlet-name>rack</servlet-name> <url-pattern>/rack/*</url-pattern></servlet-mapping>
  30. 30. # WEB-INF/config.rurequire sinatraif development? require sinatra/reloader use Rack::ShowExceptionsendrequire appset :run, falserun Sinatra::Application
  31. 31. # app.rbget /rack/ do <h1>Sinatra</h1>end
  32. 32. RESTNot just APIs...
  33. 33. URIs + HREFs Architecture of the Web
  34. 34. <a href="/vets.xml">View as XML</a>
  35. 35. <a href="/rack/vets.xml">View as XML</a>
  36. 36. In JSPs<jruby-rack:rails path="/rack/vets" params="layout=none"/>
  37. 37. Red Green Refactor Continuous improvement
  38. 38. Interceptor pattern Partial strangulation
  39. 39. Filter /owners Java// /vets /owners /1/pets Spring App
  40. 40. Filter/ /vets Ruby /owners Java// /vets /owners /1/pets Spring App
  41. 41. SpringPetclinic::Application.routes.draw do root :to => "welcome#index" resources :vetsend
  42. 42. Rails JavaRequest response response / 200 OK (N/A) 404 Not/owners 200 OK Found
  43. 43. Re-use views JSP-in-ERB
  44. 44. <%= request.render /WEB-INF/jsp/header.jsp %><%= yield %><%= request.render /WEB-INF/jsp/footer.jsp %>
  45. 45. Re-use models Hibernate + ActiveModel
  46. 46. # app/models/owner.rbjava_import org.springframework.samples.petclinic.Owner
  47. 47. # app/models/owner.rbjava_import org.springframework.samples.petclinic.Ownerclass Owner extend ActiveModel::Naming include ActiveModel::Validations include ActiveModel::Conversionend
  48. 48. # app/models/owner.rbjava_import org.springframework.samples.petclinic.Ownerclass Owner extend ActiveModel::Naming include ActiveModel::Validations include ActiveModel::Conversion validates_presence_of :first_name, :last_name, :address, :city, :telephone validates_format_of :telephone, :with => /[-0-9.+ ]+/, :message => "..."end
  49. 49. <%# app/views/owner/_form.html.erb %><%= form_for @owner do |f| %> <%= f.label :first_name %> <br/> <%= f.text_field :first_name %> <%= f.label :last_name %> <br/> <%= f.text_field :last_name %> <%# ... %><% end -%>
  50. 50. <%# app/views/owner/_form.html.erb %><%= form_for @owner do |f| %> @owner <%= f.label :first_name %> <br/> <%= f.text_field :first_name %> <%= f.label :last_name %> <br/> <%= f.text_field :last_name %> <%# ... %><% end -%>
  51. 51. Rails takes over Final strangulation
  52. 52. $ rails new petclinic --skip-active-record
  53. 53. $ mvn org.jruby.plugins:jruby-rake-plugin:classpath
  54. 54. # config/initializers/classpath.rbmodule Maven extend self CLASSPATH = [ "#{BASEDIR}/target/classes", "#{ENV[HOME]}/.m2/.../org.springframework.core-3.0.0.RELEASE.jar", # lots of jars here... ] def set_classpath require java CLASSPATH.each {|p| $CLASSPATH << p } endend
  55. 55. Maven.set_classpathmodule Spring SPRING_XML_CONFIG_FILES = [ classpath:applicationContext.xml ].to_java :string # creates a String[] CONTEXT = ClassPathXmlApplicationContext.new( SPRING_XML_CONFIG_FILES)end
  56. 56. WarblerINSTALL gem install warbler
  57. 57. # config/warble.rbWarbler::Config.new do |config| require config/initializers/classpath config.java_libs += Maven.jar_files config.java_classes = FileList["target/classes/**/*"]end
  58. 58. $ warble executable warCreating refactoring-to-rails.war$ java -jar refactoring-to-rails.war
  59. 59. Hollow out the tree
  60. 60. JRuby T-Shirts!Stop by booth #5605
  61. 61. Party Tue 6:30pmhttp://ey.io/oeuot1
  62. 62. ➡ Script Bowl Nic Williams Wed 8:30 AM–Hilton Grand Ballroom B➡ Accelerate Your Business and Aim for the Cloud with Java and JRuby Jacob Lehrbaum, Mike Piech Wed 3:00 PM–Parc 55 Embarcadero➡ Real World JRuby Charles Nutter, Thomas Enebo Wed 4:30 PM–Parc 55 Market Street
  63. 63. Imageshttp://www.flickr.com/photos/john_mcclumpha/4138419594/http://www.flickr.com/photos/phil_shirley/4500893932/http://www.flickr.com/photos/y_i/2330044065/http://www.flickr.com/photos/herzogbr/462383777/http://en.wikipedia.org/wiki/File:Sagrada_Familia_01.jpghttp://www.flickr.com/photos/koocheekoo/38407225/http://www.flickr.com/photos/27649557@N07/5000528445/http://www.flickr.com/photos/gpaumier/446059442/http://www.flickr.com/photos/ilm/12831049/http://upload.wikimedia.org/wikipedia/commons/9/95/Ryugyong_hotel_01.jpghttp://upload.wikimedia.org/wikipedia/commons/7/78/Ryugyeong_Hotel_on_February_2011.jpghttp://en.wikipedia.org/wiki/File:ExteiorShearTruss.jpghttp://en.wikipedia.org/wiki/File:ExtReenfDetail.jpghttp://en.wikipedia.org/wiki/File:Szkieleteor_in_krakow.JPGhttp://www.flickr.com/photos/epingchris/5110376533/http://www.flickr.com/photos/bazylek/3194294047/http://www.flickr.com/photos/58847482@N03/5920653295/http://www.flickr.com/photos/nancybaym/3828905896/http://www.flickr.com/photos/anitagould/5501316782/

×