Link
Embed
Share
Beginning
This slide
Copy link URL
Copy link URL
Copy iframe embed code
Copy iframe embed code
Copy javascript embed code
Copy javascript embed code
Share
Tweet
Share
Tweet
Slide 1
Slide 1 text
Big Rails
Slide 2
Slide 2 text
https://github.com/josh-jacobson/Wedloom
Slide 3
Slide 3 text
Refactoring towards Component- based Rails Architectures Stephan Hagemann ! Pivotal Labs Boulder, CO
Slide 4
Slide 4 text
Component-based Rails architectures
Slide 5
Slide 5 text
#cbra
Slide 6
Slide 6 text
No content
Slide 7
Slide 7 text
No content
Slide 8
Slide 8 text
github.com/shageman/the_next_big_thing
Slide 9
Slide 9 text
Teaser Email Signup Annoyance Event Counter Rails Container
Slide 10
Slide 10 text
Proxy Partner API Rails Container Registration Internal API
Slide 11
Slide 11 text
Availability and Booking Rails Travel Site Payment Gateway Conversion Tracking
Slide 12
Slide 12 text
Rails TV Shows with Social Network Global Admin Show Admin SMS Interface Social Network Publisher Admin UI Users and Channels
Slide 13
Slide 13 text
No content
Slide 14
Slide 14 text
WAT?
Slide 15
Slide 15 text
Because it helps
Slide 16
Slide 16 text
How to write #cbra? github.com/shageman/the_next_big_thing ! http://pivotallabs.com/tag/rails-application-suites/ ! confreaks.com/presenters/790-stephan-hagemann confreaks.com/presenters/784-ben-smith ! https://leanpub.com/cbra
Slide 17
Slide 17 text
Big Rails
Slide 18
Slide 18 text
No content
Slide 19
Slide 19 text
How Big? find . -iname "*.rb" -type f -exec cat {} \; | wc -l
Slide 20
Slide 20 text
How Big? gist.github.com/shageman/11185993
Slide 21
Slide 21 text
No content
Slide 22
Slide 22 text
No content
Slide 23
Slide 23 text
Growing size
Slide 24
Slide 24 text
No content
Slide 25
Slide 25 text
No content
Slide 26
Slide 26 text
Exploding complexity Size Possible Interactions
Slide 27
Slide 27 text
Versions of Large VS
Slide 28
Slide 28 text
No content
Slide 29
Slide 29 text
No content
Slide 30
Slide 30 text
Size Possible Interactions Reduced (Exploding) complexity
Slide 31
Slide 31 text
No content
Slide 32
Slide 32 text
the rich get richer and the poor get
Slide 33
Slide 33 text
- “Ain't We Got Fun?” - Gus Kahn, Raymond B. Egan the rich get richer and the poor get—children!
Slide 34
Slide 34 text
Preferential Attachment
Slide 35
Slide 35 text
Entities (sorted by size) Size
Slide 36
Slide 36 text
Big Open-Source Rails Apps browsercms! calagator! canvas-lms! citizenry! diaspora opencongress! opengovernment! portlandcrime! railscollab! rubygems.org locomotivecms! fat_free_crm! fulcrum! loc_counts! onebody skyline! snorby! spot-us! spree! teambox tracks
Slide 37
Slide 37 text
What About Code? find . -iname "*.rb" -type f -exec wc -l {} \; | sort -rn
Slide 38
Slide 38 text
What About Code? https://gist.github.com/shageman/11190909
Slide 39
Slide 39 text
No content
Slide 40
Slide 40 text
No content
Slide 41
Slide 41 text
user.rb
Slide 42
Slide 42 text
No content
Slide 43
Slide 43 text
ActiveRecord Associations
Slide 44
Slide 44 text
has_many
Slide 45
Slide 45 text
users model
Slide 46
Slide 46 text
id name home 1 Kate Chicago 2 Pete Boulder 3 Ian Boulder 4 Sam Chicago users table users model
Slide 47
Slide 47 text
id name code 1 red #FF0000 2 green #00FF00 3 blue #0000FF 4 yellow #FFFF00 colors table colors model
Slide 48
Slide 48 text
How many has many? ack " has_many " -c | awk -F ":" '{print $2,$1}' | grep -v "0" | sort -rn
Slide 49
Slide 49 text
How many has many? https://gist.github.com/shageman/11191030
Slide 50
Slide 50 text
No content
Slide 51
Slide 51 text
No content
Slide 52
Slide 52 text
user.rb
Slide 53
Slide 53 text
No content
Slide 54
Slide 54 text
No content
Slide 55
Slide 55 text
No content
Slide 56
Slide 56 text
we can do better
Slide 57
Slide 57 text
No content
Slide 58
Slide 58 text
No content
Slide 59
Slide 59 text
No content
Slide 60
Slide 60 text
No content
Slide 61
Slide 61 text
SOLID
Slide 62
Slide 62 text
Single Responsibility Principle
Slide 63
Slide 63 text
Things that don’t belong
Slide 64
Slide 64 text
SRP - where? Method Class Module Yes! Yes!
Slide 65
Slide 65 text
SRP - where? Method Class Namespace Yes! Yes!
Slide 66
Slide 66 text
Mixins
Slide 67
Slide 67 text
SRP - where? Method Class Namespace Component Application Now you can! Yes! Yes! You should! … Anyone? You should!
Slide 68
Slide 68 text
Components over SOAs 1 repo 1 test suite (and splittable!) 1 deployment no additional versioning constraints easier refactorings between parts
Slide 69
Slide 69 text
Within a SOA componentize your apps
Slide 70
Slide 70 text
Refactoring towards #cbra
Slide 71
Slide 71 text
No content
Slide 72
Slide 72 text
Teasing out App Component Extracting Functional Component
Slide 73
Slide 73 text
https://leanpub.com/cbra
Slide 74
Slide 74 text
Teasing out App Component
Slide 75
Slide 75 text
Teasing out App Component 0. Got tests?
Slide 76
Slide 76 text
Teasing out App Component 1. Find a vertical that makes sense on its own V C M
Slide 77
Slide 77 text
Teasing out App Component 2. Namespace controllers, views, and models V C M
Slide 78
Slide 78 text
Teasing out App Component 2. Namespace controllers, views, and models V C M
Slide 79
Slide 79 text
Teasing out App Component 3. Hunt down other dependencies V C M
Slide 80
Slide 80 text
Teasing out App Component 4. Move all namespaced code into an engine V C M
Slide 81
Slide 81 text
Teasing out App Component 4b. rails plugin new MY_NEW_COMPONENT --full --mountable V C M
Slide 82
Slide 82 text
Teasing out App Component Step 3. PROFIT! V C M
Slide 83
Slide 83 text
Teasing out App Component PROTIP: Special Case V C M M
Slide 84
Slide 84 text
Extracting Functional Component
Slide 85
Slide 85 text
Extracting Functional Component 0. Got tests?
Slide 86
Slide 86 text
Extracting Functional Component 1. Find functional component
Slide 87
Slide 87 text
Extracting Functional Component 2. bundle gem MY_NEW_COMPONENT
Slide 88
Slide 88 text
Extracting Functional Component 3. move all files into gem (and namespace)
Slide 89
Slide 89 text
Extracting Functional Component 4. move the other stuff the gem needs
Slide 90
Slide 90 text
Extracting Functional Component 5. Require the gem from your app
Slide 91
Slide 91 text
Extracting Functional Component 6. Add shims/ports/adapters to make the app happy
Slide 92
Slide 92 text
Extracting Functional Component Step 3. PROFIT!
Slide 93
Slide 93 text
No content
Slide 94
Slide 94 text
I will help @shageman
Slide 95
Slide 95 text
No content
Slide 96
Slide 96 text
No content
Slide 97
Slide 97 text
Thanks! @shageman