Apidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
Â
Engines Lightning Talk
1. The Rails
Engine That
Could?
Saturday, April 28, 2012
2. Hi!
www.launchware.com
on the InterTubes
Hiring
dpickett
on Twitter
Saturday, April 28, 2012
3. What I Can Tell You
About Rails Engines
⢠A Brief History
⢠A Rails Engine In Rails 3.1
⢠Implementation Gotchas
⢠Deployment Gotchas With Heroku
⢠Conclusions
Saturday, April 28, 2012
4. Out With The Old...
⢠Components in Rails
Beta and Rails 1
⢠Components
removed in Rails 2
Saturday, April 28, 2012
5. ...In With the New
⢠Engines in Rails 3
⢠Enginex as part of Rails 3.1
Saturday, April 28, 2012
6. Generating
rails generate plugin thomas --mountable
Saturday, April 28, 2012
9. Manage Dependencies
In Your Gemspec
Shift Your Perspective
Saturday, April 28, 2012
10. Shifting Perspectives
⢠Think like an API designer
⢠Favor composition over inheritance
⢠Obey SOLID principles for more
maintainable code
Saturday, April 28, 2012
11. Maintain Perspective
⢠Do as you would normally:
⢠Write migrations
⢠Seed data
⢠Run rake tasks
⢠Run generators
Saturday, April 28, 2012
13. Routes
⢠Routes are loaded where you mount
them
⢠Only one opportunity for placement
⢠No ďŹexibility to divide up routes for
ďŹne tuning priorities
Saturday, April 28, 2012
14. Namespacing
⢠Namespace Your Engine - it will save you lots of
pain.
⢠If you must in your consuming application, use
ActiveSupportâs require_dependency to override:
require_dependency
Thomas::Engine.root.join(âapp/models/userâ).to_s
class User < ActiveRecord::Base
#override the engine here
end
Saturday, April 28, 2012
15. Routes
⢠Routes are loaded where you mount
them
⢠Only one opportunity for placement
⢠No ďŹexibility to divide up routes for
ďŹne tuning priorities
Saturday, April 28, 2012
16. Consumer::Application do
Thomas::Routes::UserRoutes.draw(self)
#custom routes here
Thomas::Routes::ScheduleRoutes.draw(self)
end
module Thomas
module Routes
module UserRoutes
def self.draw(map)
map.instance_eval do
resources :user...
end
end
end
end
end
Saturday, April 28, 2012
17. Named Routes Helpers
⢠If you donât namespace, I found these to be
incredibly problematic
⢠You must include helpers in your
application controller and in your request
specs/tests
Saturday, April 28, 2012
18. class ApplicationController < ActionController::Base
include Thomas::Engine.routes.url_helpers
include ActionDispatch::Routing::PolymorphicRoutes
end
Youâll use these two lines a lot.
Apply when you get an undeďŹned *_path or *_url
method
Saturday, April 28, 2012
20. Devise
⢠Wiring I18n load paths is deferred until the
app comes up, disallowing override ability
Saturday, April 28, 2012
21. class Thomas::Engine < Rails::Engine
config.after_initialize do
Rails.application.config.after_initialize do
paths = I18n.load_path.delete_if do |p|
p =~ /devise-/
end
#put deviseâs default locales in its place
I18n.load_path = paths + I18n.load_path
I18n.reload!
end
end
Saturday, April 28, 2012
22. Inherited Resources
And Responders
Doesnât Work
Drops Your Responder
Saturday, April 28, 2012
25. class ApplicationController < ActionController::Base
def self.engine_inherit_resources
inherit_resources
self.responder = MobileResponder
end
end
end
Saturday, April 28, 2012
26. Deploying Private
Gems To Heroku
⢠Bundle with your github credentials in
plaintext
⢠Maintain your own gem server
⢠Write a rake task to vendor the gem and
commit when deploying
⢠NEW: http://www.gemfury.com/
Saturday, April 28, 2012
27. Overall, Engines Are
Great
⢠Thereâs still room for
improvement, but theyâre
awesome once you get
going
⢠They will challenge you as
a developer and as a Rails
Framework user
Saturday, April 28, 2012
28. Thanks!
⢠Iâll post slides @ www.launchware.com
⢠Chat me up on Twitter: @dpickett
⢠Chat me up on IRC: dpickett in #boston.rb
⢠Weâre hiring!
Saturday, April 28, 2012