Even-Darker Art of Rails Engines @lazyatom - - PowerPoint PPT Presentation

even darker art
SMART_READER_LITE
LIVE PREVIEW

Even-Darker Art of Rails Engines @lazyatom - - PowerPoint PPT Presentation

The Even-Darker Art of Rails Engines @lazyatom github.com/lazyatom/engines Rails 2.3 history November 2005 its distracting! reuse is overrated! Evil! Evil! Evil! Evil! Evil! Evil! Evil! Evil! Shit! eek! appable_plugins desert


slide-1
SLIDE 1

The

Even-Darker Art

  • f

Rails Engines

slide-2
SLIDE 2

@lazyatom

slide-3
SLIDE 3

github.com/lazyatom/engines

slide-4
SLIDE 4

Rails 2.3

slide-5
SLIDE 5

history

slide-6
SLIDE 6

November 2005

slide-7
SLIDE 7

it’s distracting!

slide-8
SLIDE 8

reuse is overrated!

slide-9
SLIDE 9

Evil!

Evil! Evil! Evil! Evil! Evil! Evil! Evil! Shit!

slide-10
SLIDE 10

eek!

slide-11
SLIDE 11

appable_plugins

slide-12
SLIDE 12

desert

slide-13
SLIDE 13

merb slices?

slide-14
SLIDE 14
slide-15
SLIDE 15

engines

slide-16
SLIDE 16

!"#$%&!"#$'#(%&$#)&!"#$%&*$+,#-.!)

!"#$%&'() $$*%&'()$++,$-'%!.%&'()./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!

slide-17
SLIDE 17

app/controllers/ models/ helpers/ views/ metal/

slide-18
SLIDE 18

*$+,#-&"**&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!

slide-19
SLIDE 19

9"-7"1$J%--

won’t load from your plugin

slide-20
SLIDE 20

Ticket #1905

slide-21
SLIDE 21

config/routes.rb

slide-22
SLIDE 22

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+'(%.!)

slide-23
SLIDE 23

top precedence

slide-24
SLIDE 24

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:

slide-25
SLIDE 25

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:

slide-26
SLIDE 26

Ticket #2592

(also Ticket #329)

slide-27
SLIDE 27

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!

slide-28
SLIDE 28

what’s missing?

slide-29
SLIDE 29

public assets

slide-30
SLIDE 30

copy

slide-31
SLIDE 31

file clash

slide-32
SLIDE 32

83+!5*$+,#-&#-%'"$$.!)

2<./2%5"6$,$H%)90%2"=0"8B@/-"=!/10%2"B..@QR4..CC$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!

slide-33
SLIDE 33

83+!5*$+,#-&#-%'"$$.!)

2<./2%5"6$,$H%)90%2"=0"8B@/-"=!/10%2"B..@QR4..CC$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)>

slide-34
SLIDE 34

migrations

slide-35
SLIDE 35

simple DSL

slide-36
SLIDE 36

rollback

slide-37
SLIDE 37

!&:2/51%)": $$VWWXWYWYYVYVZ[.%-79%=1&

version

20090101121234 20090102142345 2008123123456

VWWXWYWVY[VZ[\.&")%=1& 7-(5/0:!&:2/51%)": $$VWW]YVZYZ[\^.5%22%=1&

slide-38
SLIDE 38

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)

slide-39
SLIDE 39

it gets worse

slide-40
SLIDE 40

!&:2/51%)": $$WWY.%-79%=1&

version

001 002

WWV.&")%=1& 7-(5/0:!&:2/51%)": $$WWY.5%22%=1&

slide-41
SLIDE 41 http://www.flickr.com/photos/bk2204/475332962/
slide-42
SLIDE 42

single timeline

slide-43
SLIDE 43

app migration 1 app migration 2 plugin migration 1 app migration 3 plugin migration 2 install upgrade You Me

slide-44
SLIDE 44

app migration 1 app migration 2 plugin migration 1 app migration 3 plugin migration 2 You

slide-45
SLIDE 45

WW[.!"-)%=1& !&:2/51%)": $$WWY.%-79%=1& WWV.&")%=1& 7-(5/0:!&:2/51%)": $$WWY.5%22%=1& WWZ.7-(5/0.)'.WWY=1&

slide-46
SLIDE 46

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?

slide-47
SLIDE 47

Ticket #2058

interblah.net/plugin-migrations

slide-48
SLIDE 48

my recommendation?

(for the moment, at least)

slide-49
SLIDE 49

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)

slide-50
SLIDE 50

techniques

slide-51
SLIDE 51
  • verriding functionality
slide-52
SLIDE 52

views just work

slide-53
SLIDE 53

controllers

slide-54
SLIDE 54

straight override

slide-55
SLIDE 55
slide-56
SLIDE 56
slide-57
SLIDE 57

module

slide-58
SLIDE 58
slide-59
SLIDE 59
slide-60
SLIDE 60
slide-61
SLIDE 61

namespaced

slide-62
SLIDE 62
slide-63
SLIDE 63
slide-64
SLIDE 64
slide-65
SLIDE 65

playing nice with the class cache

slide-66
SLIDE 66

1/23*8/36/1**$#2"'#3-43-'!3$$(!/ 9"%/)((-/!(73:(;/6!37/'9(/73;+$(/ '!((/)+'/#%/%'#$$/"2'#:(< <

<

<

<

<

<<!

slide-67
SLIDE 67

O;)/D"_(77'1)JJe"7"0!"0;/"6=-'%!.'0;".7%)96

slide-68
SLIDE 68

ApplicationController AppController PluginController

slide-69
SLIDE 69

ApplicationController PluginController

slide-70
SLIDE 70

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

?%/-6JJQ0/)/%-/f"1=1(0$!'$+;'0#/5+ $$3$");=== $$;'0#/5=1"-'%!.7-(5/06$,$)1(" $$ "0!

slide-71
SLIDE 71

83+!5*$+,#-&"**&23-'!3$$(!%&,33;523-'!3$$(!.!)

;-%66$g''!I'0)1'--"1$h$=== $$(0-'%!%&-" $$ $$3$");$=== "0!

slide-72
SLIDE 72

init.rb woes

slide-73
SLIDE 73

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

785*$+,#-&#-#'.!)

$$_'2"O77I-%66="A)"0!BP<i"9%D/'(1C

slide-74
SLIDE 74

testing

slide-75
SLIDE 75

ApplicationController PluginController AppController

slide-76
SLIDE 76

ApplicationController PluginController Their Code Your Code

slide-77
SLIDE 77
slide-78
SLIDE 78
slide-79
SLIDE 79
slide-80
SLIDE 80

unit test?

slide-81
SLIDE 81

test in your own rails environment?

slide-82
SLIDE 82

plugin_test_helper

slide-83
SLIDE 83

I care about testing my chunk

slide-84
SLIDE 84

You care about testing your whole app

slide-85
SLIDE 85

empower the developer

slide-86
SLIDE 86

avoiding fail

slide-87
SLIDE 87

;%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!

slide-88
SLIDE 88

consume wisely

slide-89
SLIDE 89

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%

slide-90
SLIDE 90

you will not be able to write some engines.

slide-91
SLIDE 91

you will not be able to use some engines.

slide-92
SLIDE 92

extract specific functionality

slide-93
SLIDE 93

establish some clear integration points

slide-94
SLIDE 94

you are customer #1

slide-95
SLIDE 95

READ the CODE

slide-96
SLIDE 96

james@lazyatom.com lets@gofreerange.com

FIN