Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
The Even Darker Art of Rails Engines
Search
lazyatom
May 05, 2009
Programming
1
490
The Even Darker Art of Rails Engines
Given at RailsConf 2009
lazyatom
May 05, 2009
Tweet
Share
More Decks by lazyatom
See All by lazyatom
Here's to the crazy ones
lazyatom
1
790
Why is nobody using Refinements?
lazyatom
0
1k
Deploying Rails with Docker
lazyatom
5
750
IoT Printer
lazyatom
0
390
Do we need any more test frameworks?
lazyatom
0
54
Gem That (2009)
lazyatom
0
370
The Dark Art of Rails Plugins
lazyatom
0
390
Extending Rails with Plugins (2007)
lazyatom
0
270
Engines: Team Development on Rails
lazyatom
0
450
Other Decks in Programming
See All in Programming
React 19でお手軽にCSS-in-JSを自作する
yukukotani
5
560
Findy Team+ Awardを受賞したかった!ベストプラクティス応募内容をふりかえり、開発生産性向上もふりかえる / Findy Team Plus Award BestPractice and DPE Retrospective 2024
honyanya
0
140
LLM Supervised Fine-tuningの理論と実践
datanalyticslabo
8
1.9k
オニオンアーキテクチャを使って、 Unityと.NETでコードを共有する
soi013
0
370
見えないメモリを観測する: PHP 8.4 `pg_result_memory_size()` とSQL結果のメモリ管理
kentaroutakeda
0
930
shadcn/uiを使ってReactでの開発を加速させよう!
lef237
0
300
Jaspr Dart Web Framework 박제창 @Devfest 2024
itsmedreamwalker
0
150
混沌とした例外処理とエラー監視に秩序をもたらす
morihirok
13
2.2k
各クラウドサービスにおける.NETの対応と見解
ymd65536
0
250
知られざるDMMデータエンジニアの生態 〜かつてツチノコと呼ばれし者〜
takaha4k
1
410
AWSのLambdaで PHPを動かす選択肢
rinchoku
2
390
テストコードのガイドライン 〜作成から運用まで〜
riku929hr
7
1.4k
Featured
See All Featured
Statistics for Hackers
jakevdp
797
220k
Designing Dashboards & Data Visualisations in Web Apps
destraynor
230
52k
[RailsConf 2023 Opening Keynote] The Magic of Rails
eileencodes
28
9.2k
"I'm Feeling Lucky" - Building Great Search Experiences for Today's Users (#IAC19)
danielanewman
226
22k
Responsive Adventures: Dirty Tricks From The Dark Corners of Front-End
smashingmag
251
21k
Distributed Sagas: A Protocol for Coordinating Microservices
caitiem20
330
21k
Building a Modern Day E-commerce SEO Strategy
aleyda
38
7k
Gamification - CAS2011
davidbonilla
80
5.1k
The MySQL Ecosystem @ GitHub 2015
samlambert
250
12k
For a Future-Friendly Web
brad_frost
176
9.5k
Producing Creativity
orderedlist
PRO
343
39k
The Art of Programming - Codeland 2020
erikaheidi
53
13k
Transcript
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! Evil! Evil! Shit!
eek!
appable_plugins
desert
merb slices?
None
engines
!"#$%&!"#$'#(%&$#)&!"#$%&*$+,#-.!) !"#$%&'() $$*%&'()$++,$-'%!.%&'()./0#'12%)/'0 "0! 3$405/0"6$%1"$7-(5/06$8/)9$%0$%77:$!/1";)'1<= !"#$"05/0"> $$9%6.%77.!/1";)'1<> "0! 3$?")(106$)1("$/#$)9"$"05/0"$69/76$8/)9$%$1'()/05$#/-" !"#$1'()"!>
$$@/-"="A/6)>B1'()/05.#/-"C "0! !"#$D/"8.7%)9 $$@/-"=E'/0B!/1";)'1<F$G%77GF$GD/"86GC "0!
app/controllers/ models/ helpers/ views/ metal/
*$+,#-&"**&23-'!3$$(!&*$+,#-523-'!3$$(!.!) ;-%66$H-(5/0I'0)1'--"1/0/1**$#2"'#3-43-'!3$$(! $$!"#$/0!"A $$$$1"0!"1$J)"A)$,K$LM"--'F$H-(5/0NL $$"0! "0!
9"-7"1$J%-- won’t load from your plugin
Ticket #1905
config/routes.rb
O;)/'0I'0)1'--"1JJ?'()/05JJ?'()"6=!1%8$!'$+2%7+ $$2%7=;'00";)$G:7%)9GF$J;'0)1'--"1$,K$L7-(5/0LF$ $$$$$$$$$$$$$$$$$$$$$$$J%;)/'0$,K$L/0!"AL "0! *$+,#-&23-6#,&!3+'(%.!)
top precedence
O;)/'0I'0)1'--"1JJ?'()/05JJ?'()"6=!1%8$!'$+2%7+ $$2%7=;'00";)$G:7%)9GF$J;'0)1'--"1$,K$L7-(5/0LF$ $$$$$$$$$$$$$$$$$$$$$$$J%;)/'0$,K$L/0!"AL "0! O;)/'0I'0)1'--"1JJ?'()/05JJ?'()"6=!1%8$!'$+2%7+ $$3$===$')9"1$1'()"6$=== $$2%7=;'00";)$G:7%)9GF$J;'0)1'--"1$,K$L%77LF$ $$$$$$$$$$$$$$$$$$$$$$$J%;)/'0$,K$L/0!"AL $$3$===$')9"1$1'()"6$=== "0!
in your plugin: in your app:
O;)/'0I'0)1'--"1JJ?'()/05JJ?'()"6=!1%8$!'$+2%7+ $$2%7=;'00";)$G:7%)9GF$J;'0)1'--"1$,K$L7-(5/0LF$ $$$$$$$$$$$$$$$$$$$$$$$J%;)/'0$,K$L/0!"AL "0! O;)/'0I'0)1'--"1JJ?'()/05JJ?'()"6=!1%8$!'$+2%7+ $$3$===$')9"1$1'()"6$=== $$2%7=;'00";)$G:7%)9GF$J;'0)1'--"1$,K$L%77LF$ $$$$$$$$$$$$$$$$$$$$$$$J%;)/'0$,K$L/0!"AL $$3$===$')9"1$1'()"6$=== "0!
in your plugin: in your app:
Ticket #2592 (also Ticket #329)
785*$+,#-&$#)&785*$+,#-.!) 2'!(-"$P<H-(5/0 $$!"#$6"-#=%!!.1'()"6B7"*C $$$$2%7=;'00";)$L:6)(##LF$J;'0)1'--"1$,K$L)9/056L $$"0! "0! O;)/'0I'0)1'--"1JJ?'()/05JJ?'()"6=!1%8$!'$+2%7+ $$3$<'(1$%77$1'()"6=== $$P<H-(5/0=%!!.1'()"6B2%7C $$3$");===
"0!
what’s missing?
public assets
copy
file clash
83+!5*$+,#-&#-%'"$$.!) 2<./2%5"6$,$H%)90%2"=0"8B@/-"=!/10%2"
[email protected]
$S$ $$$$$$$$$$$$$$L%66")6:/2%5"6L )%15")$,$?%/-6=1'')$S$L7(&-/;:/2%5"6:2<.7-(5/0L @/-"T)/-6=2U!/1.7B)%15")C 2<./2%5"6=;9/-!1"0="%;9$!'$+"+$ $$$$@/-"T)/-6=;7.1B"F$)%15")$S$"=&%6"0%2"C$ "0!
83+!5*$+,#-&#-%'"$$.!) 2<./2%5"6$,$H%)90%2"=0"8B@/-"=!/10%2"
[email protected]
$S$ $$$$$$$$$$$$$$L%66")6:/2%5"6L )%15")$,$?%/-6=1'')$S$L7(&-/;:/2%5"6:2<.7-(5/0L )%15")=2%U".6<2-/0UB2<./2%5"6C$(0-"66$)%15")="A/6)>
migrations
simple DSL
rollback
!&:2/51%)": $$VWWXWYWYYVYVZ[.%-79%=1& version 20090101121234 20090102142345 2008123123456 VWWXWYWVY[VZ[\.&")%=1& 7-(5/0:!&:2/51%)": $$VWW]YVZYZ[\^.5%22%=1&
version 20090101121234 20090102142345 2008123123456 1%U"$!&J1'--&%;U P/51%)'1=1'--&%;U P/51%)'13;(11"0).D"16/'0 P/51%)'132/51%)"!=-%6) P/51%)'1=5").%--.D"16/'06 BL_4R4I`$D"16/'0$@?aP$
$ $ $$6;9"2%.2/51%)/'06LC =2%7BbJ)'./C=6'1)
it gets worse
!&:2/51%)": $$WWY.%-79%=1& version 001 002 WWV.&")%=1& 7-(5/0:!&:2/51%)": $$WWY.5%22%=1&
http://www.flickr.com/photos/bk2204/475332962/
single timeline
app migration 1 app migration 2 plugin migration 1 app
migration 3 plugin migra install upgrade You Me
app migration 1 app migration 2 plugin migration 1 app
migration 3 plugin migration 2 You
WW[.!"-)%=1& !&:2/51%)": $$WWY.%-79%=1& WWV.&")%=1& 7-(5/0:!&:2/51%)": $$WWY.5%22%=1& WWZ.7-(5/0.)'.WWY=1&
WW[.!"-)%=1& !&:2/51%)": $$WWY.%-79%=1& WWV.&")%=1& 7-(5/0:!&:2/51%)": $$WWY.5%22%=1& WWZ.7-(5/0.)'.WWY=1& Copy & Retimestamp?
Reference? Symlink?
Ticket #2058 interblah.net/plugin-migrations
my recommendation? (for the moment, at least)
write a generator c$6;1/7):5"0"1%)"$%;)6.%6.#(.2/51%)/'06 $$$$ $$$"A/6)6$$!&:2/51%)" $$$;1"%)"$$!&:2/51%)":VWWXW\W\YYYZZd.&-%9=1& c$=== (within your
plugin)
techniques
overriding functionality
views just work
controllers
straight override
None
None
module
None
None
None
namespaced
None
None
None
playing nice with the class cache
1/23*8/36/1**$#2"'#3-43-'!3$$(!/ 9"%/)((-/!(73:(;/6!37/'9(/73;+$(/ '!((/)+'/#%/%'#$$/"2'#:(<< < < < < < < !
O;)/D"_(77'1)JJe"7"0!"0;/"6=-'%!.'0;".7%)96
ApplicationController AppController PluginController
ApplicationController PluginController
23-6#,&(-:#!3-7(-'.!) ?%/-6JJQ0/)/%-/f"1=1(0$!'$+;'0#/5+ $$3$");=== $$;'0#/5=1"-'%!.7-(5/06$,$)1(" $$ "0!
83+!5*$+,#-&"**&23-'!3$$(!%&,33;523-'!3$$(!.!) ;-%66$g''!I'0)1'--"1$h$=== $$(0-'%!%&-" $$ $$3$");$=== "0!
init.rb woes
;'0#/5=)'.71"7%1"$!' $$ "0! 785*$+,#-&#-#'.!) $$_'2"O77I-%66="A)"0!BP<i"9%D/'(1C
testing
ApplicationController PluginController AppController
ApplicationController PluginController Their Code Your Code
None
! " # $
None
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
;%6"$;'!"=;'06(2"1 $$89"0$;'!"=%()9'1 $$$$1"(6"=2'6)-<$,j$:"##";)/D": $$89"0$1%0!B!"D"-'7"1C $$$$1"(6"=)1/;U/"1.&().7'66/&-"B)1("C $$"-6" $$$$1"(6"='D"11%)"!N "0!
consume wisely
Serving Size 14 kloc Nutrition Facts Amount Per Serving 1
bad engine Calories 10,666 Long Methods 1578g 34% God Objects 326g 7% Stress 320mg 119% Total Fat 2674g 98% Hairloss 45g 45.8% % Daily Value* Technical Debt 13g 87% Untested Code 1578mg 34% Hidden Bugs 326mg 7% Benefit 1mg 0.1%
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
[email protected]
[email protected]
FIN