Upgrade to Pro — share decks privately, control downloads, hide ads and more …

How I architected my big Rails app for success!...

How I architected my big Rails app for success! (RubyConfAU 2014)

Avatar for Benjamin Smith

Benjamin Smith

February 20, 2014
Tweet

More Decks by Benjamin Smith

Other Decks in Technology

Transcript

  1. How I architected my big Rails app for success! Benjamin

    Smith @benjamin_smith Thursday, February 20, 14
  2. success • long project • big dev team • lots

    of code • scalable • big 1st release @benjamin_smith Thursday, February 20, 14
  3. success • long project • big dev team • lots

    of code • scalable • big 1st release @benjamin_smith Thursday, February 20, 14
  4. the product • Multimedia content publishing • A social network

    • iOS app for consumers (using JSON API) • CMS (Rails) for admins @benjamin_smith Thursday, February 20, 14
  5. s/engine_template/new_engine_name/g s/EngineTemplate/NewEngineName/g for file in $(find . -name "*engine_template*") do

    mv $file `echo $file | sed s/engine_template/$1/` done @benjamin_smith Thursday, February 20, 14
  6. s/gem_template/new_gem_name/g s/GemTemplate/NewGemName/g for file in $(find . -name "*gem_template*") do

    mv $file `echo $file | sed s/gem_template/$1/` done @benjamin_smith Thursday, February 20, 14
  7. self contained engines • all tables namespaced • migrations •

    tests @benjamin_smith Thursday, February 20, 14
  8. module EngineWithMigrations class Engine < ::Rails::Engine isolate_namespace EngineWithMigrations initializer :append_migrations

    do |app| unless app.root.to_s.match root.to_s app.config.paths["db/migrate"] += config.paths["db/migrate"].expanded end end end end http://pivotallabs.com/leave-your-migrations-in-your-rails- engines/ Thursday, February 20, 14
  9. self contained engines • all tables namespaced • migrations •

    tests @benjamin_smith Thursday, February 20, 14
  10. class User < ActiveRecord::Base has_many :posts end class Post <

    ActiveRecord::Base belongs_to :user end Thursday, February 20, 14
  11. domain api • simple classes to wrap ActiveRecord calls •

    take as input: params or ids • output PORO @benjamin_smith Thursday, February 20, 14
  12. class UserManager def find_by_id(id) User.new(UserRecord.find(id)) end private class UserRecord <

    ActiveRecord::Base validates :email, presence: true end end Thursday, February 20, 14
  13. class UserManager def find_by_id(id) User.new(UserRecord.find(id)) end private class UserRecord <

    ActiveRecord::Base validates :email, presence: true end end Thursday, February 20, 14
  14. class UserManager def find_by_id(id) User.new(UserRecord.find(id)) end private class UserRecord <

    ActiveRecord::Base validates :email, presence: true end end Thursday, February 20, 14
  15. class UserManager def find_by_id(id) User.new(UserRecord.find(id)) end private class UserRecord <

    ActiveRecord::Base validates :email, presence: true end end class User def initialize(user_record) self.email = user_record.email end end Thursday, February 20, 14
  16. class PostManager def find_all_by_user_id(user_id) PostRecord.where(user_id: user_id) # ... convert to

    PORO ... end end post_manager = PostManager.new @posts = post_manager.find_all_by_user_id(@user.id) Thursday, February 20, 14
  17. class UserManager def find_by_id(id) User.new(UserRecord.find(id)) end end user_manager = UserManager.new

    author = user_manager.find_by_id(@post.user_id) Thursday, February 20, 14
  18. I live my life one green build at a time

    Thursday, February 20, 14
  19. engines are a pain... • LOW velocity for first 4-6

    weeks • client worries • opposite of Rails • one pair to start is a MUST • some technical hurtles • must be diligent about refactoring • monkey patching Rails @benjamin_smith Thursday, February 20, 14
  20. ... but they get better • no slow down in

    development time • they age well • easier parallel development • potential for scaling • smart and fast build scripts @benjamin_smith Thursday, February 20, 14
  21. class UserManager def find_by_id(id) User.new(UserRecord.find(id)) end private class UserRecord <

    ActiveRecord::Base validates :email, presence: true end end Thursday, February 20, 14