The

Even-Darker Art
        of

  Rails Engines
@lazyatom
github.com/lazyatom/engines
Rails 2.3
history
November 2005
it’s distracting!
reuse is overrated!
Evil!     Evil!
 Evil!

                                   Evil!

Evil!            Evil!
                                 ...
eek!
appable_plugins
desert
merb slices?
engines
!quot;#$%&!quot;#$'#(%&$#)&!quot;#$%&*$+,#-.!)
!quot;#$%&'()
$$*%&'()$++,$-'%!.%&'()./0#'12%)/'0
quot;0!

3$405/0quot;6$%1...
app/controllers/
    models/
    helpers/
    views/
    metal/
*$+,#-"**&23-'!3$$(!&*$+,#-523-'!3$$(!.!)

 ;-%66$H-(5/0I'0)1'--quot;1/0/1**$#2quot;'#3-43-'!3$$(!
 $$!quot;#$/0!quot...
9quot;-7quot;1$J%--
won’t load from your plugin
Ticket #1905
config/routes.rb
*$+,#-&23-6#,&!3+'(%.!)



  O;)/'0I'0)1'--quot;1JJ?'()/05JJ?'()quot;6=!1%8$!'$+2%7+

  $$2%7=;'00quot;;)$G:7%)9GF$J;'0)1'...
top precedence
in your plugin:
 O;)/'0I'0)1'--quot;1JJ?'()/05JJ?'()quot;6=!1%8$!'$+2%7+
 $$2%7=;'00quot;;)$G:7%)9GF$J;'0)1'--quot;1$,K$L7...
in your plugin:
 O;)/'0I'0)1'--quot;1JJ?'()/05JJ?'()quot;6=!1%8$!'$+2%7+
 $$2%7=;'00quot;;)$G:7%)9GF$J;'0)1'--quot;1$,K$L7...
Ticket #2592
(also Ticket #329)
785*$+,#-&$#)&785*$+,#-.!)
2'!(-quot;$P<H-(5/0
$$!quot;#$6quot;-#=%!!.1'()quot;6B7quot;*C
$$$$2%7=;'00quot;;)$L:6)(##LF$J;...
what’s missing?
public assets
copy
file clash
83+!5*$+,#-&#-%'quot;$$.!)

2<./2%5quot;6$,$H%)90%2quot;=0quot;8B@/-quot;=!/10%2quot;B..@QR4..CC$S$
$$$$$$$$$$$$$$L%66quot...
83+!5*$+,#-&#-%'quot;$$.!)

2<./2%5quot;6$,$H%)90%2quot;=0quot;8B@/-quot;=!/10%2quot;B..@QR4..CC$S$
$$$$$$$$$$$$$$L%66quot...
migrations
simple DSL
rollback
version       !&:2/51%)quot;:
                 $$VWWXWYWYYVYVZ[.%-79%=1&
20090101121234     VWWXWYWVY[VZ[.&quot;)%=1&

200...
version       1%Uquot;$!&J1'--&%;U
                  P/51%)'1=1'--&%;U
20090101121234
                  P/51%)'13;(11quot;...
it gets worse
version   !&:2/51%)quot;:
          $$WWY.%-79%=1&
 001        WWV.&quot;)%=1&

 002
          7-(5/0:!&:2/51%)quot;:
    ...
http://www.flickr.com/photos/bk2204/475332962/
single timeline
You                             1
                               tio n
                        ig  ra           tio n1
   ...
tio n1
You           i gra              n1
            m                tio
      app              mi gra
                ...
!&:2/51%)quot;:
$$WWY.%-79%=1&
  WWV.&quot;)%=1&
  WWZ.7-(5/0.)'.WWY=1&
  WW[.!quot;-)%=1&


7-(5/0:!&:2/51%)quot;:
$$WWY....
Symlink?
 !&:2/51%)quot;:
 $$WWY.%-79%=1&
   WWV.&quot;)%=1&
Reference?
   WWZ.7-(5/0.)'.WWY=1&
   WW[.!quot;-)%=1&


 7-(...
Ticket #2058
interblah.net/plugin-migrations
my recommendation?
   (for the moment, at least)
write a generator
              (within your plugin)



c$6;1/7):5quot;0quot;1%)quot;$%;)6.%6.#(.2/51%)/'06
$$$$
$$$quot;A...
techniques
overriding functionality
views just work
controllers
straight override
module
namespaced
playing nice with the
     class cache
1/23*8/36/1**$#2quot;'#3-43-'!3$$(!/

                            <
'!((/)+'/#%/%'#$$/quot;2'#:(<< < <
                   ...
O;)/Dquot;_(77'1)JJequot;7quot;0!quot;0;/quot;6=-'%!.'0;quot;.7%)96
ApplicationController




AppController                 PluginController
ApplicationController




                  PluginController
23-6#,&(-:#!3-7(-'.!)


 ?%/-6JJQ0/)/%-/fquot;1=1(0$!'$+;'0#/5+
 $$3$quot;);===

 $$;'0#/5=1quot;-'%!.7-(5/06$,$)1(quot;
 ...
83+!5*$+,#-&quot;**&23-'!3$$(!%&,33;523-'!3$$(!.!)



  ;-%66$g''!I'0)1'--quot;1$h$===
  $$(0-'%!%&-quot;
  $$
  $$3$quot;...
init.rb woes
785*$+,#-&#-#'.!)



;'0#/5=)'.71quot;7%1quot;$!'

$$_'2quot;O77I-%66=quot;A)quot;0!BP<iquot;9%D/'(1C
$$
quot;0!
testing
ApplicationController




AppController                 PluginController
ApplicationController



                           ir C ode
                        The

                         Your Co...
quot;
    $
    !
#
unit test?
test in your own rails
    environment?
plugin_test_helper
I care about testing
     my chunk
You care about testing
   your whole app
empower the
 developer
avoiding fail
;%6quot;$;'!quot;=;'06(2quot;1

$$89quot;0$;'!quot;=%()9'1
$$$$1quot;(6quot;=2'6)-<$,j$:quot;##quot;;)/Dquot;:

$$89quot;0...
consume wisely
Nutrition Facts
Serving Size 14 kloc
Amount Per Serving 1 bad engine
Calories 10,666
                    % Daily Value*
To...
you will not be able to
 write some engines.
you will not be able to
  use some engines.
extract
specific functionality
establish some
clear integration points
you are customer #1
READ the CODE
james@lazyatom.com




  FIN
lets@gofreerange.com
The Even Darker Art Of Rails Engines
The Even Darker Art Of Rails Engines
The Even Darker Art Of Rails Engines
The Even Darker Art Of Rails Engines
The Even Darker Art Of Rails Engines
The Even Darker Art Of Rails Engines
The Even Darker Art Of Rails Engines
The Even Darker Art Of Rails Engines
The Even Darker Art Of Rails Engines
The Even Darker Art Of Rails Engines
The Even Darker Art Of Rails Engines
Prochain SlideShare
Chargement dans…5
×

The Even Darker Art Of Rails Engines

2 250 vues

Publié le

The Rails Engines presentation given by James Adam at RailsConf 2009.

Publié dans : Technologie
0 commentaire
6 j’aime
Statistiques
Remarques
  • Soyez le premier à commenter

Aucun téléchargement
Vues
Nombre de vues
2 250
Sur SlideShare
0
Issues des intégrations
0
Intégrations
1 018
Actions
Partages
0
Téléchargements
30
Commentaires
0
J’aime
6
Intégrations 0
Aucune incorporation

Aucune remarque pour cette diapositive

The Even Darker Art Of Rails Engines

  1. 1. The Even-Darker Art of Rails Engines
  2. 2. @lazyatom
  3. 3. github.com/lazyatom/engines
  4. 4. Rails 2.3
  5. 5. history
  6. 6. November 2005
  7. 7. it’s distracting!
  8. 8. reuse is overrated!
  9. 9. Evil! Evil! Evil! Evil! Evil! Evil! Evil! Evil! Shit!
  10. 10. eek!
  11. 11. appable_plugins
  12. 12. desert
  13. 13. merb slices?
  14. 14. engines
  15. 15. !quot;#$%&!quot;#$'#(%&$#)&!quot;#$%&*$+,#-.!) !quot;#$%&'() $$*%&'()$++,$-'%!.%&'()./0#'12%)/'0 quot;0! 3$405/0quot;6$%1quot;$7-(5/06$8/)9$%0$%77:$!/1quot;;)'1<= !quot;#$quot;05/0quot;> $$9%6.%77.!/1quot;;)'1<> quot;0! 3$?quot;)(106$)1(quot;$/#$)9quot;$quot;05/0quot;$69/76$8/)9$%$1'()/05$#/-quot; !quot;#$1'()quot;!> $$@/-quot;=quot;A/6)>B1'()/05.#/-quot;C quot;0! !quot;#$D/quot;8.7%)9 $$@/-quot;=E'/0B!/1quot;;)'1<F$G%77GF$GD/quot;86GC quot;0!
  16. 16. app/controllers/ models/ helpers/ views/ metal/
  17. 17. *$+,#-&quot;**&23-'!3$$(!&*$+,#-523-'!3$$(!.!) ;-%66$H-(5/0I'0)1'--quot;1/0/1**$#2quot;'#3-43-'!3$$(! $$!quot;#$/0!quot;A $$$$1quot;0!quot;1$J)quot;A)$,K$LMquot;--'F$H-(5/0NL $$quot;0! quot;0!
  18. 18. 9quot;-7quot;1$J%-- won’t load from your plugin
  19. 19. Ticket #1905
  20. 20. config/routes.rb
  21. 21. *$+,#-&23-6#,&!3+'(%.!) O;)/'0I'0)1'--quot;1JJ?'()/05JJ?'()quot;6=!1%8$!'$+2%7+ $$2%7=;'00quot;;)$G:7%)9GF$J;'0)1'--quot;1$,K$L7-(5/0LF$ $$$$$$$$$$$$$$$$$$$$$$$J%;)/'0$,K$L/0!quot;AL quot;0!
  22. 22. top precedence
  23. 23. in your plugin: O;)/'0I'0)1'--quot;1JJ?'()/05JJ?'()quot;6=!1%8$!'$+2%7+ $$2%7=;'00quot;;)$G:7%)9GF$J;'0)1'--quot;1$,K$L7-(5/0LF$ $$$$$$$$$$$$$$$$$$$$$$$J%;)/'0$,K$L/0!quot;AL quot;0! in your app: O;)/'0I'0)1'--quot;1JJ?'()/05JJ?'()quot;6=!1%8$!'$+2%7+ $$3$===$')9quot;1$1'()quot;6$=== $$2%7=;'00quot;;)$G:7%)9GF$J;'0)1'--quot;1$,K$L%77LF$ $$$$$$$$$$$$$$$$$$$$$$$J%;)/'0$,K$L/0!quot;AL $$3$===$')9quot;1$1'()quot;6$=== quot;0!
  24. 24. in your plugin: O;)/'0I'0)1'--quot;1JJ?'()/05JJ?'()quot;6=!1%8$!'$+2%7+ $$2%7=;'00quot;;)$G:7%)9GF$J;'0)1'--quot;1$,K$L7-(5/0LF$ $$$$$$$$$$$$$$$$$$$$$$$J%;)/'0$,K$L/0!quot;AL quot;0! in your app: O;)/'0I'0)1'--quot;1JJ?'()/05JJ?'()quot;6=!1%8$!'$+2%7+ $$3$===$')9quot;1$1'()quot;6$=== $$2%7=;'00quot;;)$G:7%)9GF$J;'0)1'--quot;1$,K$L%77LF$ $$$$$$$$$$$$$$$$$$$$$$$J%;)/'0$,K$L/0!quot;AL $$3$===$')9quot;1$1'()quot;6$=== quot;0!
  25. 25. Ticket #2592 (also Ticket #329)
  26. 26. 785*$+,#-&$#)&785*$+,#-.!) 2'!(-quot;$P<H-(5/0 $$!quot;#$6quot;-#=%!!.1'()quot;6B7quot;*C $$$$2%7=;'00quot;;)$L:6)(##LF$J;'0)1'--quot;1$,K$L)9/056L $$quot;0! quot;0! O;)/'0I'0)1'--quot;1JJ?'()/05JJ?'()quot;6=!1%8$!'$+2%7+ $$3$<'(1$%77$1'()quot;6=== $$P<H-(5/0=%!!.1'()quot;6B2%7C $$3$quot;);=== quot;0!
  27. 27. what’s missing?
  28. 28. public assets
  29. 29. copy
  30. 30. file clash
  31. 31. 83+!5*$+,#-&#-%'quot;$$.!) 2<./2%5quot;6$,$H%)90%2quot;=0quot;8B@/-quot;=!/10%2quot;B..@QR4..CC$S$ $$$$$$$$$$$$$$L%66quot;)6:/2%5quot;6L )%15quot;)$,$?%/-6=1'')$S$L7(&-/;:/2%5quot;6:2<.7-(5/0L @/-quot;T)/-6=2U!/1.7B)%15quot;)C 2<./2%5quot;6=;9/-!1quot;0=quot;%;9$!'$+quot;+$ $$$$@/-quot;T)/-6=;7.1Bquot;F$)%15quot;)$S$quot;=&%6quot;0%2quot;C$ quot;0!
  32. 32. 83+!5*$+,#-&#-%'quot;$$.!) 2<./2%5quot;6$,$H%)90%2quot;=0quot;8B@/-quot;=!/10%2quot;B..@QR4..CC$S$ $$$$$$$$$$$$$$L%66quot;)6:/2%5quot;6L )%15quot;)$,$?%/-6=1'')$S$L7(&-/;:/2%5quot;6:2<.7-(5/0L )%15quot;)=2%Uquot;.6<2-/0UB2<./2%5quot;6C$(0-quot;66$)%15quot;)=quot;A/6)>
  33. 33. migrations
  34. 34. simple DSL
  35. 35. rollback
  36. 36. version !&:2/51%)quot;: $$VWWXWYWYYVYVZ[.%-79%=1& 20090101121234 VWWXWYWVY[VZ[.&quot;)%=1& 20090102142345 7-(5/0:!&:2/51%)quot;: 2008123123456 $$VWW]YVZYZ[^.5%22%=1&
  37. 37. version 1%Uquot;$!&J1'--&%;U P/51%)'1=1'--&%;U 20090101121234 P/51%)'13;(11quot;0).Dquot;16/'0 20090102142345 P/51%)'132/51%)quot;!=-%6) 2008123123456 P/51%)'1=5quot;).%--.Dquot;16/'06 BL_4R4I`$Dquot;16/'0$@?aP$$ $$6;9quot;2%.2/51%)/'06LC =2%7BbJ)'./C=6'1)
  38. 38. it gets worse
  39. 39. version !&:2/51%)quot;: $$WWY.%-79%=1& 001 WWV.&quot;)%=1& 002 7-(5/0:!&:2/51%)quot;: $$WWY.5%22%=1&
  40. 40. http://www.flickr.com/photos/bk2204/475332962/
  41. 41. single timeline
  42. 42. You 1 tio n ig ra tio n1 app m mi gra lug in tio n2 p i gra 3 Me pp m at ion a igr nst all ap pm ig ra i nm plu gi ra de u pg
  43. 43. tio n1 You i gra n1 m tio app mi gra gin tio n2 plu ra pm ig tio n3 ap ig ra n2 pm tio ap mi gra plu gin
  44. 44. !&:2/51%)quot;: $$WWY.%-79%=1& WWV.&quot;)%=1& WWZ.7-(5/0.)'.WWY=1& WW[.!quot;-)%=1& 7-(5/0:!&:2/51%)quot;: $$WWY.5%22%=1&
  45. 45. Symlink? !&:2/51%)quot;: $$WWY.%-79%=1& WWV.&quot;)%=1& Reference? WWZ.7-(5/0.)'.WWY=1& WW[.!quot;-)%=1& 7-(5/0:!&:2/51%)quot;: Copy & Retimestamp? $$WWY.5%22%=1&
  46. 46. Ticket #2058 interblah.net/plugin-migrations
  47. 47. my recommendation? (for the moment, at least)
  48. 48. write a generator (within your plugin) c$6;1/7):5quot;0quot;1%)quot;$%;)6.%6.#(.2/51%)/'06 $$$$ $$$quot;A/6)6$$!&:2/51%)quot; $$$;1quot;%)quot;$$!&:2/51%)quot;:VWWXWWYYYZZd.&-%9=1& c$===
  49. 49. techniques
  50. 50. overriding functionality
  51. 51. views just work
  52. 52. controllers
  53. 53. straight override
  54. 54. module
  55. 55. namespaced
  56. 56. playing nice with the class cache
  57. 57. 1/23*8/36/1**$#2quot;'#3-43-'!3$$(!/ < '!((/)+'/#%/%'#$$/quot;2'#:(<< < < << ! 9quot;%/)((-/!(73:(;/6!37/'9(/73;+$(/ <
  58. 58. O;)/Dquot;_(77'1)JJequot;7quot;0!quot;0;/quot;6=-'%!.'0;quot;.7%)96
  59. 59. ApplicationController AppController PluginController
  60. 60. ApplicationController PluginController
  61. 61. 23-6#,&(-:#!3-7(-'.!) ?%/-6JJQ0/)/%-/fquot;1=1(0$!'$+;'0#/5+ $$3$quot;);=== $$;'0#/5=1quot;-'%!.7-(5/06$,$)1(quot; $$ quot;0!
  62. 62. 83+!5*$+,#-&quot;**&23-'!3$$(!%&,33;523-'!3$$(!.!) ;-%66$g''!I'0)1'--quot;1$h$=== $$(0-'%!%&-quot; $$ $$3$quot;);$=== quot;0!
  63. 63. init.rb woes
  64. 64. 785*$+,#-&#-#'.!) ;'0#/5=)'.71quot;7%1quot;$!' $$_'2quot;O77I-%66=quot;A)quot;0!BP<iquot;9%D/'(1C $$ quot;0!
  65. 65. testing
  66. 66. ApplicationController AppController PluginController
  67. 67. ApplicationController ir C ode The Your Code PluginController
  68. 68. quot; $ ! #
  69. 69. unit test?
  70. 70. test in your own rails environment?
  71. 71. plugin_test_helper
  72. 72. I care about testing my chunk
  73. 73. You care about testing your whole app
  74. 74. empower the developer
  75. 75. avoiding fail
  76. 76. ;%6quot;$;'!quot;=;'06(2quot;1 $$89quot;0$;'!quot;=%()9'1 $$$$1quot;(6quot;=2'6)-<$,j$:quot;##quot;;)/Dquot;: $$89quot;0$1%0!B!quot;Dquot;-'7quot;1C $$$$1quot;(6quot;=)1/;U/quot;1.&().7'66/&-quot;B)1(quot;C $$quot;-6quot; $$$$1quot;(6quot;='Dquot;11%)quot;!N quot;0!
  77. 77. consume wisely
  78. 78. Nutrition Facts Serving Size 14 kloc Amount Per Serving 1 bad engine Calories 10,666 % Daily Value* Total Fat 2674g 98% Long Methods 1578g 34% God Objects 326g 7% Stress 320mg 119% Hairloss 45g 45.8% Technical Debt 13g 87% Untested Code 1578mg 34% Hidden Bugs 326mg 7% Benefit 1mg 0.1%
  79. 79. you will not be able to write some engines.
  80. 80. you will not be able to use some engines.
  81. 81. extract specific functionality
  82. 82. establish some clear integration points
  83. 83. you are customer #1
  84. 84. READ the CODE
  85. 85. james@lazyatom.com FIN lets@gofreerange.com

×