SlideShare a Scribd company logo
1 of 39
Download to read offline
COWBOYS & ENGINES
Fernand Galiana
Tuesday, September 17, 13
HISTORY
0.14.2 ~ 2005
2.3 ~ 2009 -- Engine support
3.0 ~ 2010 --Yehuda and crew
Tuesday, September 17, 13
SURPRISE?
> rails c
> Rails::Application.ancestors
=> [Rails::Application, Rails::Engine,...]
Tuesday, September 17, 13
IMPETUS?
Mini rails apps [MVC|Assets|lib]
Divide conquer
Reusable components
Decoupling
Performance
Tuesday, September 17, 13
ENGINE TYPES
full
mountable
Tuesday, September 17, 13
CREATE!
> rails plugin new engines/blee [opts]
Tuesday, September 17, 13
NOTABLES...
--full
--mountable
-T
-B
-d [mysql|pg|sqlite3|etc...]
-j [jquery|coffeescript]
-dummy_path
Tuesday, September 17, 13
CREATE!
> rails plugin new engines/cowboy 
--mountable -T -B
--dummy-path=spec/dummy 
-j coffeescript -d mysql
Tuesday, September 17, 13
TEH BROG!
You rock, bro!
Tuesday, September 17, 13
LAB I
git clone https://github.com/derailed/ng_training
git checkout -b lab_1
follow the README!
Tuesday, September 17, 13
ANATOMY
Tuesday, September 17, 13
STRUCTURE
cowboy_engine
o app
o bin
o config
o lib
o spec
Tuesday, September 17, 13
STRUCTURE
cowboy_engine
o app
o assets
o controllers
o helpers
o models
o views
o bin
o ...
Tuesday, September 17, 13
STRUCTURE
cowboy_engine
o app
o controllers
o cowboy_engine
o cowboys_controller.rb
o ...
o bin
o ...
Tuesday, September 17, 13
ENGINE GEMSPEC
Gem::Specification.new do |s|
s.name = "pilgrim"
s.version = Pilgrim::VERSION
s.authors = ["Fernand"]
s.email = ["fernand.galiana@gmail.com"]
s.homepage = "http://pilgrim"
s.summary = "Pilgrim’s engine"
s.description = "Pilgrim’s engine"
s.files = Dir["{app,config,db,lib}/**/*", "MIT-LICENSE", "Rakefile", "README.rdoc"]
s.add_dependency 'rails' , '~> 4.0.0'
s.add_dependency 'bootstrap-sass' , '~> 2.3.2.2'
s.add_dependency 'font-awesome-sass-rails', '~> 3.0.2.2'
s.add_development_dependency "mysql2" , '~> 0.3.13'
s.add_development_dependency 'rspec-rails' , '~> 2.14.0'
end
Tuesday, September 17, 13
THE ENGINE
module Cowboy
class Engine < ::Rails::Engine
isolate_namespace
config.autoload_paths += [File.join( self.root, %w[lib blee] )]
end
end
Tuesday, September 17, 13
BUSINESS AS USUAL
rails g [model|controller|migration]
custom generators
engine initializers
Tuesday, September 17, 13
GEMFILE
gem ‘cowboy’, path:‘engines/cowboy’
my_app/Gemfile
Tuesday, September 17, 13
CONVENIENCE
Cowboy::Engine.root
Cowboy::Engine.helpers
Cowboy::Engine.routes.url_helpers
Tuesday, September 17, 13
MIGRATIONS
Tuesday, September 17, 13
MIGRATIONS
> rake cowboy:install:migrations
Tuesday, September 17, 13
MIGRATIONS
rake db:migrate SCOPE=Cowboy
Tuesday, September 17, 13
MONKEYMIGS!
module Cowboy
class Engine < ::Rails::Engine
isolate_namespace Cowboy
initializer :append_migrations do |app|
next if app.root.to_s.match self.root.to_s
config.paths["db/migrate"].expanded.each do |expanded_path|
app.config.paths["db/migrate"] << expanded_path
end
end
end
end
Tuesday, September 17, 13
ISOLATED MODELS
table names expects engine_name_table_name
self.table_name = :guns
or
table_name_prefix = “”
Tuesday, September 17, 13
ROUTING
Tuesday, September 17, 13
engines/cowboy/config/routes.rb
ENGINE ROUTES
Cowboy::Engine.routes.draw do
resources :guns, only: [:create]
resources :belt do
resources :ammos
end
end
Tuesday, September 17, 13
APP ROUTES
Rango::Application.routes.draw do
root 'welcome#index'
mount Cowboy::Engine => '/pilgrim', as: :cowboy_ng
resources :jenkins do
resources :bullets, controller: 'cowboy/bullets'
end
end
rango/config/routes.rb
Tuesday, September 17, 13
CONTEXT MATTERS!
Cowboy engine context
guns_path => /guns
main_app.welcome_path => /welcome
Main Application context
cowboy_ng.guns_path => /pilgrims/guns
welcome_path => /welcome
Tuesday, September 17, 13
my_app/controllers/guns_controller.rb
HELPERS
class GunsController < ApplicationController
helper Cowboy::BulletsHelper
...
end
Tuesday, September 17, 13
ENGINE ASSETS
stylesheet_link_tag cowboy/guns.css
javascript_include_tag cowboy/guns.js
or
*=require cowboy/guns
//=require cowboy/guns
Tuesday, September 17, 13
PARTIALS
render gun => render partial:‘cowboy/...’, object: gun
render :partial ‘fred’ => render :partial ‘cowboy/fred’
Tuesday, September 17, 13
LOADING ORDER
config.railties_order = [Cowboy::Engine, :main_app, :all]
Tuesday, September 17, 13
TESTING
Tuesday, September 17, 13
TESTING (RSPEC)
spec/dummy
Tuesday, September 17, 13
TESTING (RSPEC)
config.include Dummy::Application.routes.url_helpers
use_route :cowboy
Tuesday, September 17, 13
LAB II
Scenario: Other models in the system need to be
commentable. Spin out this functionality as a new
‘social’ engine
Tuesday, September 17, 13
CHEAT
> rails plugin new engines/social -T --mountable 
-j coffeescript -B -d mysql 
--dummy-path=spec/dummy
Tuesday, September 17, 13
LAB III
Scenario: PM wants a reporting admin ui to track
comments. In light of this new feature commenting
behavior needs to be shared across several engines.
Refactor social engine to depend on the new
common engine
Tuesday, September 17, 13
Q&A
Get a rope?
Tuesday, September 17, 13

More Related Content

What's hot

Puppet Camp Atlanta 2014: Continuous Deployment of Puppet Modules
Puppet Camp Atlanta 2014: Continuous Deployment of Puppet ModulesPuppet Camp Atlanta 2014: Continuous Deployment of Puppet Modules
Puppet Camp Atlanta 2014: Continuous Deployment of Puppet Modules
Puppet
 
Advanced WordPress Development Environments
Advanced WordPress Development EnvironmentsAdvanced WordPress Development Environments
Advanced WordPress Development Environments
Beau Lebens
 
Html5 awesomeness
Html5 awesomenessHtml5 awesomeness
Html5 awesomeness
senthil_hi
 

What's hot (20)

Perl Dancer for Python programmers
Perl Dancer for Python programmersPerl Dancer for Python programmers
Perl Dancer for Python programmers
 
Writing webapps with Perl Dancer
Writing webapps with Perl DancerWriting webapps with Perl Dancer
Writing webapps with Perl Dancer
 
An introduction to Rex - FLOSS UK DevOps York 2015
An introduction to Rex - FLOSS UK DevOps York 2015An introduction to Rex - FLOSS UK DevOps York 2015
An introduction to Rex - FLOSS UK DevOps York 2015
 
Puppet Camp Atlanta 2014: Continuous Deployment of Puppet Modules
Puppet Camp Atlanta 2014: Continuous Deployment of Puppet ModulesPuppet Camp Atlanta 2014: Continuous Deployment of Puppet Modules
Puppet Camp Atlanta 2014: Continuous Deployment of Puppet Modules
 
Intro to Rails
Intro to Rails Intro to Rails
Intro to Rails
 
Workshop 21: React Router
Workshop 21: React RouterWorkshop 21: React Router
Workshop 21: React Router
 
Continuous deployment of puppet modules
Continuous deployment of puppet modulesContinuous deployment of puppet modules
Continuous deployment of puppet modules
 
Dancing Tutorial
Dancing TutorialDancing Tutorial
Dancing Tutorial
 
Csharp_Contents
Csharp_ContentsCsharp_Contents
Csharp_Contents
 
Advanced WordPress Development Environments
Advanced WordPress Development EnvironmentsAdvanced WordPress Development Environments
Advanced WordPress Development Environments
 
App Lego
App LegoApp Lego
App Lego
 
Html5 awesomeness
Html5 awesomenessHtml5 awesomeness
Html5 awesomeness
 
Killer page load performance
Killer page load performanceKiller page load performance
Killer page load performance
 
Using WordPress as your application stack
Using WordPress as your application stackUsing WordPress as your application stack
Using WordPress as your application stack
 
WordPress as the Backbone(.js)
WordPress as the Backbone(.js)WordPress as the Backbone(.js)
WordPress as the Backbone(.js)
 
Sinatra
SinatraSinatra
Sinatra
 
Running Node.js in Production using Passenger
Running Node.js in Production using PassengerRunning Node.js in Production using Passenger
Running Node.js in Production using Passenger
 
The story became happy with itamae
The story became happy with itamaeThe story became happy with itamae
The story became happy with itamae
 
Hyperlink
HyperlinkHyperlink
Hyperlink
 
Monitoring web application behaviour with cucumber-nagios
Monitoring web application behaviour with cucumber-nagiosMonitoring web application behaviour with cucumber-nagios
Monitoring web application behaviour with cucumber-nagios
 

Viewers also liked (6)

In The Land Of Graphs...
In The Land Of Graphs...In The Land Of Graphs...
In The Land Of Graphs...
 
Bucket List Item #1246
Bucket List Item #1246Bucket List Item #1246
Bucket List Item #1246
 
Ingenious
IngeniousIngenious
Ingenious
 
Advanced Topics Snippets Lib Meter Zbw Hh Workshop
Advanced Topics Snippets Lib Meter Zbw Hh WorkshopAdvanced Topics Snippets Lib Meter Zbw Hh Workshop
Advanced Topics Snippets Lib Meter Zbw Hh Workshop
 
What's new in Rails5?
What's new in Rails5?What's new in Rails5?
What's new in Rails5?
 
Docker Container Orchestration
Docker Container OrchestrationDocker Container Orchestration
Docker Container Orchestration
 

Similar to Engines

[jqconatx] Adaptive Images for Responsive Web Design
[jqconatx] Adaptive Images for Responsive Web Design[jqconatx] Adaptive Images for Responsive Web Design
[jqconatx] Adaptive Images for Responsive Web Design
Christopher Schmitt
 
Migrating Legacy Rails Apps to Rails 3
Migrating Legacy Rails Apps to Rails 3Migrating Legacy Rails Apps to Rails 3
Migrating Legacy Rails Apps to Rails 3
Clinton Dreisbach
 

Similar to Engines (20)

Plug it on!... with railties
Plug it on!... with railtiesPlug it on!... with railties
Plug it on!... with railties
 
[jqconatx] Adaptive Images for Responsive Web Design
[jqconatx] Adaptive Images for Responsive Web Design[jqconatx] Adaptive Images for Responsive Web Design
[jqconatx] Adaptive Images for Responsive Web Design
 
Keeping it small - Getting to know the Slim PHP micro framework
Keeping it small - Getting to know the Slim PHP micro frameworkKeeping it small - Getting to know the Slim PHP micro framework
Keeping it small - Getting to know the Slim PHP micro framework
 
Building a Startup Stack with AngularJS
Building a Startup Stack with AngularJSBuilding a Startup Stack with AngularJS
Building a Startup Stack with AngularJS
 
Rails Sojourn: One Man's Journey - Wicked Good Ruby Conference 2013
Rails Sojourn: One Man's Journey - Wicked Good Ruby Conference 2013Rails Sojourn: One Man's Journey - Wicked Good Ruby Conference 2013
Rails Sojourn: One Man's Journey - Wicked Good Ruby Conference 2013
 
Rapid Prototyping FTW!!!
Rapid Prototyping FTW!!!Rapid Prototyping FTW!!!
Rapid Prototyping FTW!!!
 
Customizer-ing Theme Options: A Visual Playground
Customizer-ing Theme Options: A Visual PlaygroundCustomizer-ing Theme Options: A Visual Playground
Customizer-ing Theme Options: A Visual Playground
 
Intro tobackbone
Intro tobackboneIntro tobackbone
Intro tobackbone
 
Redmine Betabeers SVQ
Redmine Betabeers SVQRedmine Betabeers SVQ
Redmine Betabeers SVQ
 
Backbone
BackboneBackbone
Backbone
 
Dependency management & Package management in JavaScript
Dependency management & Package management in JavaScriptDependency management & Package management in JavaScript
Dependency management & Package management in JavaScript
 
How to set up and test a Rails 3 Engine
How to set up and test a Rails 3 EngineHow to set up and test a Rails 3 Engine
How to set up and test a Rails 3 Engine
 
Rails engines
Rails enginesRails engines
Rails engines
 
Migrating Legacy Rails Apps to Rails 3
Migrating Legacy Rails Apps to Rails 3Migrating Legacy Rails Apps to Rails 3
Migrating Legacy Rails Apps to Rails 3
 
Dev In Rio 2009
Dev In Rio 2009Dev In Rio 2009
Dev In Rio 2009
 
Generators
GeneratorsGenerators
Generators
 
Rails Engine | Modular application
Rails Engine | Modular applicationRails Engine | Modular application
Rails Engine | Modular application
 
Oredev 2013: Building Web Apps with Ember.js
Oredev 2013: Building Web Apps with Ember.jsOredev 2013: Building Web Apps with Ember.js
Oredev 2013: Building Web Apps with Ember.js
 
Cors michael
Cors michaelCors michael
Cors michael
 
浜松Rails3道場 其の壱 プロジェクト作成〜Rouging編
浜松Rails3道場 其の壱 プロジェクト作成〜Rouging編浜松Rails3道場 其の壱 プロジェクト作成〜Rouging編
浜松Rails3道場 其の壱 プロジェクト作成〜Rouging編
 

More from Fernand Galiana (6)

GraphQLUs For The RestOfUs!
GraphQLUs For The RestOfUs!GraphQLUs For The RestOfUs!
GraphQLUs For The RestOfUs!
 
Sailing into 2018 with Kubernetes and Istio
Sailing into 2018 with Kubernetes and IstioSailing into 2018 with Kubernetes and Istio
Sailing into 2018 with Kubernetes and Istio
 
GraphQL, The New Black?
GraphQL, The New Black?GraphQL, The New Black?
GraphQL, The New Black?
 
You, Mix and Kubee
You, Mix and KubeeYou, Mix and Kubee
You, Mix and Kubee
 
R-House (LSRC)
R-House (LSRC)R-House (LSRC)
R-House (LSRC)
 
Rhouse - Home automation is ruby ?
Rhouse - Home automation is ruby ?Rhouse - Home automation is ruby ?
Rhouse - Home automation is ruby ?
 

Recently uploaded

Recently uploaded (20)

Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
 
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation Strategies
 

Engines