Refactoring Rails Apps with Engines

Refactoring Rails Apps with Engines

Having an app broken into small, loosely coupled, highly cohesive components is great. Using Rails Engines is one way to do this, but how do you take an existing monolithic Rails app and convert it to use Engines?

This talk will walk through Benjamin’s experience of refactoring a Rails codebase with zero Engines to an architecture with 40 different Rails Engines. He will also compare and contrast with another Rails application he built from the ground up using an Engines architecture. Not only will this talk include lessons learned, it will also feature concrete step by step instructions needed to smoothly refactor your codebase into an Engines based architecture.

6d48d3849102b57bbc1462c0da0b3866?s=128

Benjamin Smith

September 17, 2015
Tweet

Transcript

  1. Refactoring Rails Apps with Engines Benjamin Smith @benjamin_smith

  2. Why should you care about Engines? @benjamin_smith

  3. rails new my_cute_little_app @benjamin_smith

  4. Features Time

  5. None
  6. @benjamin_smith

  7. None
  8. 1 Year @benjamin_smith

  9. 2 Years @benjamin_smith

  10. 3+ Year @benjamin_smith

  11. Features Time @benjamin_smith

  12. None
  13. @benjamin_smith

  14. Engines to the Rescue! @benjamin_smith

  15. None
  16. Rails @benjamin_smith

  17. Rails @benjamin_smith

  18. What is an Engine anyway? @benjamin_smith

  19. None
  20. Engines for Architecture @benjamin_smith

  21. @benjamin_smith

  22. @benjamin_smith

  23. @benjamin_smith

  24. @benjamin_smith

  25. Engines from Day 1 @benjamin_smith

  26. @benjamin_smith

  27. @benjamin_smith

  28. Engines from Day 182.5 @benjamin_smith

  29. class User < ActiveRecord::Base @benjamin_smith

  30. @benjamin_smith

  31. None
  32. None
  33. None
  34. None
  35. None
  36. None
  37. None
  38. None
  39. None
  40. Features Time @benjamin_smith

  41. Features Time @benjamin_smith

  42. None
  43. None
  44. None
  45. Exact lowest level dependencies first @benjamin_smith

  46. has_many ? @benjamin_smith

  47. None
  48. no has_many @benjamin_smith

  49. @user.posts @benjamin_smith

  50. Post.where(user_id: @user.id) @benjamin_smith

  51. Post.for_user_id(@user.id) @benjamin_smith

  52. None
  53. None
  54. Tests within Engines @benjamin_smith

  55. None
  56. what about controllers and views? @benjamin_smith

  57. @benjamin_smith

  58. controllers and views all in the Main Rails App @benjamin_smith

  59. One model and table per Engine @benjamin_smith

  60. Lots of Engines @benjamin_smith

  61. Lots of Engines @benjamin_smith

  62. Refactor as you go @benjamin_smith

  63. 1 month of existing code == 1 week of refactoring

    @benjamin_smith
  64. None
  65. A Web of Engines @benjamin_smith

  66. Product Owner Architecture @benjamin_smith

  67. None
  68. None
  69. Aggregate Engines @benjamin_smith

  70. None
  71. None
  72. None
  73. None
  74. None
  75. None
  76. None
  77. None
  78. None
  79. None
  80. None
  81. None
  82. None
  83. None
  84. Features Time @benjamin_smith

  85. None
  86. None
  87. Thanks! @benjamin_smith

  88. @benjamin_smith Component Based Rails Architecture Info cbra.info

  89. Come find me for questions! @benjamin_smith cbra.info