Refactoring Rails applications with RubyMine
-
Upload
andrzej-krzywda -
Category
Technology
-
view
224 -
download
0
Transcript of Refactoring Rails applications with RubyMine
![Page 1: Refactoring Rails applications with RubyMine](https://reader034.fdocuments.net/reader034/viewer/2022052413/55b6e58abb61eb92688b45ca/html5/thumbnails/1.jpg)
Refactoring Rails apps with RubyMine
Andrzej Krzywda Arkency
![Page 2: Refactoring Rails applications with RubyMine](https://reader034.fdocuments.net/reader034/viewer/2022052413/55b6e58abb61eb92688b45ca/html5/thumbnails/2.jpg)
Andrzej Krzywda
• Arkency
• Rails since 2004
• hundreds of Rails projects reviewed
![Page 3: Refactoring Rails applications with RubyMine](https://reader034.fdocuments.net/reader034/viewer/2022052413/55b6e58abb61eb92688b45ca/html5/thumbnails/3.jpg)
Agenda
• Typical Rails problems
• Beyond The Rails Way - new patterns
• Refactoring recipes with RubyMine
![Page 4: Refactoring Rails applications with RubyMine](https://reader034.fdocuments.net/reader034/viewer/2022052413/55b6e58abb61eb92688b45ca/html5/thumbnails/4.jpg)
Rails is great• In the first month of development
• Quick results in almost no code
• Quick feedback loop
• Predictable speed
• Your customer loves you
• You love Rails
![Page 5: Refactoring Rails applications with RubyMine](https://reader034.fdocuments.net/reader034/viewer/2022052413/55b6e58abb61eb92688b45ca/html5/thumbnails/5.jpg)
2.months.later
![Page 6: Refactoring Rails applications with RubyMine](https://reader034.fdocuments.net/reader034/viewer/2022052413/55b6e58abb61eb92688b45ca/html5/thumbnails/6.jpg)
Typical Rails problems
• MVC is not enough
• first regression bugs
• slow tests
• slower progress
![Page 7: Refactoring Rails applications with RubyMine](https://reader034.fdocuments.net/reader034/viewer/2022052413/55b6e58abb61eb92688b45ca/html5/thumbnails/7.jpg)
6.months.later
![Page 8: Refactoring Rails applications with RubyMine](https://reader034.fdocuments.net/reader034/viewer/2022052413/55b6e58abb61eb92688b45ca/html5/thumbnails/8.jpg)
Typical Rails problems
• hidden dependencies
• implicit assumptions (aka Convention over Configuration)
• security bugs!
• Rails upgrades are now projects on their own with (huge) budgets
![Page 9: Refactoring Rails applications with RubyMine](https://reader034.fdocuments.net/reader034/viewer/2022052413/55b6e58abb61eb92688b45ca/html5/thumbnails/9.jpg)
2.years.later
![Page 10: Refactoring Rails applications with RubyMine](https://reader034.fdocuments.net/reader034/viewer/2022052413/55b6e58abb61eb92688b45ca/html5/thumbnails/10.jpg)
Typical Rails problems
![Page 11: Refactoring Rails applications with RubyMine](https://reader034.fdocuments.net/reader034/viewer/2022052413/55b6e58abb61eb92688b45ca/html5/thumbnails/11.jpg)
Any questions so far?
![Page 12: Refactoring Rails applications with RubyMine](https://reader034.fdocuments.net/reader034/viewer/2022052413/55b6e58abb61eb92688b45ca/html5/thumbnails/12.jpg)
New guidelines
• explicit > implicit
• reducing meta
• more building blocks
![Page 13: Refactoring Rails applications with RubyMine](https://reader034.fdocuments.net/reader034/viewer/2022052413/55b6e58abb61eb92688b45ca/html5/thumbnails/13.jpg)
New patterns
• Inspired by:
• DDD
• Hexagonal Architecture
• DCI
• CQRS/Event Sourcing
![Page 14: Refactoring Rails applications with RubyMine](https://reader034.fdocuments.net/reader034/viewer/2022052413/55b6e58abb61eb92688b45ca/html5/thumbnails/14.jpg)
The building blocks• Service objects
• Repositories
• Adapters
• Form objects
• Domain objects
• RubyMine
![Page 15: Refactoring Rails applications with RubyMine](https://reader034.fdocuments.net/reader034/viewer/2022052413/55b6e58abb61eb92688b45ca/html5/thumbnails/15.jpg)
![Page 16: Refactoring Rails applications with RubyMine](https://reader034.fdocuments.net/reader034/viewer/2022052413/55b6e58abb61eb92688b45ca/html5/thumbnails/16.jpg)
Extract a service object
• the gateway drug
• a training in refactoring
• turn a controller action into a method object
![Page 17: Refactoring Rails applications with RubyMine](https://reader034.fdocuments.net/reader034/viewer/2022052413/55b6e58abb61eb92688b45ca/html5/thumbnails/17.jpg)
Questions?
![Page 18: Refactoring Rails applications with RubyMine](https://reader034.fdocuments.net/reader034/viewer/2022052413/55b6e58abb61eb92688b45ca/html5/thumbnails/18.jpg)
Typical controller coupling• new-action uses the ‘new’ view
• create-action uses the ‘new’ view
• edit-action uses the ‘new’ view
• ‘new’ view uses _form partial
• ‘edit’ view uses _form partial
• ‘edit’ action uses ‘edit’ view
• ‘update’ action uses ‘edit’ view
![Page 19: Refactoring Rails applications with RubyMine](https://reader034.fdocuments.net/reader034/viewer/2022052413/55b6e58abb61eb92688b45ca/html5/thumbnails/19.jpg)
newcreate
edit
update
new.haml
edit.haml_form.haml
show.rsb
common/error_messages.rsb
![Page 20: Refactoring Rails applications with RubyMine](https://reader034.fdocuments.net/reader034/viewer/2022052413/55b6e58abb61eb92688b45ca/html5/thumbnails/20.jpg)
The filters algebra
• Filters depending on each other
• The order is important
• Hard to decouple
• communication via @ivars
![Page 21: Refactoring Rails applications with RubyMine](https://reader034.fdocuments.net/reader034/viewer/2022052413/55b6e58abb61eb92688b45ca/html5/thumbnails/21.jpg)
At the controllers/views level everything is communicating
with each other via @ivars
![Page 22: Refactoring Rails applications with RubyMine](https://reader034.fdocuments.net/reader034/viewer/2022052413/55b6e58abb61eb92688b45ca/html5/thumbnails/22.jpg)
Everything is depending on instance variables
![Page 23: Refactoring Rails applications with RubyMine](https://reader034.fdocuments.net/reader034/viewer/2022052413/55b6e58abb61eb92688b45ca/html5/thumbnails/23.jpg)
Controller instance variables are the global,
mutable state
![Page 24: Refactoring Rails applications with RubyMine](https://reader034.fdocuments.net/reader034/viewer/2022052413/55b6e58abb61eb92688b45ca/html5/thumbnails/24.jpg)
the Redmine project• a project management tool
• contains a time-tracking module
• http://www.redmine.org/projects/redmine/wiki/RedmineTimeTracking
• since 2007
• https://github.com/redmine/redmine
![Page 25: Refactoring Rails applications with RubyMine](https://reader034.fdocuments.net/reader034/viewer/2022052413/55b6e58abb61eb92688b45ca/html5/thumbnails/25.jpg)
![Page 26: Refactoring Rails applications with RubyMine](https://reader034.fdocuments.net/reader034/viewer/2022052413/55b6e58abb61eb92688b45ca/html5/thumbnails/26.jpg)
![Page 27: Refactoring Rails applications with RubyMine](https://reader034.fdocuments.net/reader034/viewer/2022052413/55b6e58abb61eb92688b45ca/html5/thumbnails/27.jpg)
![Page 28: Refactoring Rails applications with RubyMine](https://reader034.fdocuments.net/reader034/viewer/2022052413/55b6e58abb61eb92688b45ca/html5/thumbnails/28.jpg)
RubyMine coding
• look at the existing concerns
• run the subset of tests
• keep refactoring
![Page 29: Refactoring Rails applications with RubyMine](https://reader034.fdocuments.net/reader034/viewer/2022052413/55b6e58abb61eb92688b45ca/html5/thumbnails/29.jpg)
![Page 30: Refactoring Rails applications with RubyMine](https://reader034.fdocuments.net/reader034/viewer/2022052413/55b6e58abb61eb92688b45ca/html5/thumbnails/30.jpg)
Summary
• Typical Rails problems
• Refactoring example
• RubyMine support
![Page 32: Refactoring Rails applications with RubyMine](https://reader034.fdocuments.net/reader034/viewer/2022052413/55b6e58abb61eb92688b45ca/html5/thumbnails/32.jpg)
Fearless Refactoring: Rails
ControllersToday 20% off with the
JETBRAINS coupon code!
http://rails-refactoring.com
![Page 33: Refactoring Rails applications with RubyMine](https://reader034.fdocuments.net/reader034/viewer/2022052413/55b6e58abb61eb92688b45ca/html5/thumbnails/33.jpg)
Thank you!
Questions?