SlideShare a Scribd company logo
HOW TO SETUP AND
TEST RAILS 3 ENGINES.




              Nicholas Faiz,
   Tree Falling In The Woods, Pty Ltd.
INTRO

A quick introduction to Engines in Rails 3, including
a demo of how to set one up and test it.

Background: I've been working on a Rails 3 engine
project since February or so. It might help if I share
what I've encountered so far.

Rails 3 Engines are new. Rails 3 RC 2 only released a
few days ago.
INTRO 2


Finding information on how to set up an Engine in
Rails 3 has been difficult. Useful blogs: http://
www.themodestrubyist.com - by Jordan West. 4 posts
about engines.

Cesario: http://www.dev-fr.com/archives/
2010/04/07/rails-3-railties-and-engines/
STORY OF ENGINES SO
         FAR




Engines before Rails 2.3
                             Engines Incorporated 2.3




         Engines revamped in Rails 3
STORY OF ENGINES ... 2

How were they revamped in Rails 3? Merb influence
of decoupling.

2009 Merb merged with Rails. Merb influence r.e.
decoupled dependencies! e.g. Should be able to use
whichever ORM in your MVC.

In Rails 3 engines revamped, now inherit from
Rails::Railtie (See the Merb influence)
WHAT ARE RAILTIES?

Railties are a central concept to Rails 3. They
decouple components from each other.

See http://railsapi.com/doc/rails-v3.0.0.beta.3/
classes/Rails/Railtie.html

All major aspects of the Rails Framework are now
assembled into a larger system via a collection of
Railties.
WHAT ARE RAILTIES? 2


ActionController::Railtie < Rails::Railtie,
ActionView::Railtie < Rails::Railtie, etc.

Railties carry initializers, letting you configure how a
Rails application is bootstrapped.’

initializer "configure something" {|app|
config.something()}
WHAT ARE ENGINES?

Rails 3: Engines *are* Railties, well, subclasses of
them.

Rails::Engine < Rails::Railties

In fact, every Rails application *is* an engine, well, a
subclass ...

Rails::Application < Rails::Engine
WHAT ARE ENGINES?


Only touching upon functionality in this
presentation.

Hosting applications can use them, or override them
if they want to change things.

Most known Rails 3 engine at the moment - Devise:
http://github.com/plataformatec/devise
CONFIGURE, BUNDLE,
       TEST
Engines are a bit more than just a Rails application,
though. More to it than the API. You have to know
how to configure, bundle, and test it.

You bundle a Rails engine, in its own gem, to reuse
within another Rails application.

First understand how an engine is accessed and used
by a Rails application.

Standard Rails app. paths available in the engine ...
ENGINE PATHS
class MyEngine < Rails::Engine
 paths.app           = "app"
 paths.app.controllers = "app/controllers"
 paths.app.helpers       = "app/helpers"
 paths.app.models         = "app/models"
 paths.app.metals        = "app/metal"
 paths.app.views         = "app/views"
 paths.lib         = "lib"
 paths.lib.tasks      = "lib/tasks"
 paths.config          = "config"
 paths.config.initializers = "config/initializers"
 paths.config.locales = "config/locales"
 paths.config.routes      = "config/routes.rb"
end
ENGINES INSIDE THE
      HOST APP.


All of this information is addressable via the Rails
object.

ruby-1.8.7-p299 > Rails.application.railties.engines

Holds an array of engine objects.
PATHS IN RAILS
                           ENGINES

    rails console

    ruby-1.8.7-p299 > e = Rails.application.railties.engines.last

    ruby-1.8.7-p299 > e.config.paths.app
a    => #<Rails::Paths::Path:0x103bf7058 @eager_load=true, @root=#<Rails::Paths::Root:
    0x103c02958 @all_paths=[#<Rails::Paths::Path:0x103bf7058 ...>, …, @paths=["app"]>

    ruby-1.8.7-p299 > e.class.name
     => "InklingContent::Engine" #helps to give your Railtie an informative namespace
FINDING AN ENGINE
      BLUEPRINT
I began working on my own engines and made
headway in some areas but not others.

I decided that I wanted a simple blueprint of how an
engine should look.

Because engines are new, there aren't established
practices for setting them up and testing them. I've
come up with my own, which seem like common
sense, but took some thought.
TOMMY THE RAILS 3
      ENGINE!


So I created Tommy, a
simple application with
a picture of Tommy the
Tank engine repeating a
message held in sqlite.
HOW IS SOMETHING SO
  SIMPLE HELPFUL?

Demonstrates some basic concepts. Some projects
would actually copy their static files - javascripts,
partials, etc. - *over* the hosting application. (e.g.
BrowserCMS), in the Rails 2.x days.

I needed to prove how sharing assets was done
without this intrusion in Rails 3.
IN DEMO LOOK FOR ...

The Railties file (the engine).

Generators for migrations.

How to share static assets (like images, stylesheets,
javascript files, etc.), from the engine into the host
engine.

How to share rake tasks.

How to configure rspec and cucumber in an engine.
TOMMY THE RAILS 3
    ENGINE DEMO




http://github.com/biv/tommy
SUMMATION


An engine can't be used without a functioning Rails
app.. I find it easiest to nest a Rails app beneath the
top directory.

Tests for the engine can be created at the top level
directory of the engine, but symlinked into the test
app..
SUMMATION 2




Rails 3 engines are new. I haven’t heard many stories,
yet, about how they perform in production settings.
CONTACT ME TO
     DISCUSS ENGINES

I’m basing a lot of work in 2010/2011 on the Engine
structure. I’m happy to discuss them:



biv/brain_in_vat on #roro freenode

http://twitter.com/nicholasf

More Related Content

What's hot

Rails Engine Patterns
Rails Engine PatternsRails Engine Patterns
Rails Engine Patterns
Andy Maleh
 
Rails 3
Rails 3Rails 3
Rails 3
Iain Hecker
 
Creating your own framework on top of Symfony2 Components
Creating your own framework on top of Symfony2 ComponentsCreating your own framework on top of Symfony2 Components
Creating your own framework on top of Symfony2 Components
Deepak Chandani
 
Railsguide
RailsguideRailsguide
Railsguidelanlau
 
Rack
RackRack
Laravel Restful API and AngularJS
Laravel Restful API and AngularJSLaravel Restful API and AngularJS
Laravel Restful API and AngularJSBlake Newman
 
Web service with Laravel
Web service with LaravelWeb service with Laravel
Web service with Laravel
Abuzer Firdousi
 
RoR 101: Session 5
RoR 101: Session 5RoR 101: Session 5
RoR 101: Session 5
Rory Gianni
 
Ruby w/o Rails (Олександр Сімонов)
Ruby w/o Rails (Олександр Сімонов)Ruby w/o Rails (Олександр Сімонов)
Ruby w/o Rails (Олександр Сімонов)
Fwdays
 
Apikit from command line
Apikit from command lineApikit from command line
Apikit from command line
fedefortin
 
Web services with laravel
Web services with laravelWeb services with laravel
Web services with laravel
Confiz
 
Be Happy With Ruby on Rails - Ecosystem
Be Happy With Ruby on Rails - EcosystemBe Happy With Ruby on Rails - Ecosystem
Be Happy With Ruby on Rails - Ecosystem
Lucas Renan
 
RoR 101: Session 3
RoR 101: Session 3RoR 101: Session 3
RoR 101: Session 3
Rory Gianni
 
Custom URL Re-Writing/Routing using Attribute Routes in MVC 4 Web APIs
Custom URL Re-Writing/Routing using Attribute Routes in MVC 4 Web APIsCustom URL Re-Writing/Routing using Attribute Routes in MVC 4 Web APIs
Custom URL Re-Writing/Routing using Attribute Routes in MVC 4 Web APIs
Akhil Mittal
 
Rest api titouan benoit
Rest api   titouan benoitRest api   titouan benoit
Rest api titouan benoit
Titouan BENOIT
 
RoR 101: Session 2
RoR 101: Session 2RoR 101: Session 2
RoR 101: Session 2
Rory Gianni
 
Rack is Spectacular
Rack is SpectacularRack is Spectacular
Rack is Spectacular
Bryce Kerley
 
Be happy with Ruby on Rails - CEUNSP Itu
Be happy with Ruby on Rails - CEUNSP ItuBe happy with Ruby on Rails - CEUNSP Itu
Be happy with Ruby on Rails - CEUNSP Itu
Lucas Renan
 

What's hot (20)

Rails Engine Patterns
Rails Engine PatternsRails Engine Patterns
Rails Engine Patterns
 
Rails engines
Rails enginesRails engines
Rails engines
 
Rails 3
Rails 3Rails 3
Rails 3
 
Creating your own framework on top of Symfony2 Components
Creating your own framework on top of Symfony2 ComponentsCreating your own framework on top of Symfony2 Components
Creating your own framework on top of Symfony2 Components
 
Railsguide
RailsguideRailsguide
Railsguide
 
Cocoa on-rails-3rd
Cocoa on-rails-3rdCocoa on-rails-3rd
Cocoa on-rails-3rd
 
Rack
RackRack
Rack
 
Laravel Restful API and AngularJS
Laravel Restful API and AngularJSLaravel Restful API and AngularJS
Laravel Restful API and AngularJS
 
Web service with Laravel
Web service with LaravelWeb service with Laravel
Web service with Laravel
 
RoR 101: Session 5
RoR 101: Session 5RoR 101: Session 5
RoR 101: Session 5
 
Ruby w/o Rails (Олександр Сімонов)
Ruby w/o Rails (Олександр Сімонов)Ruby w/o Rails (Олександр Сімонов)
Ruby w/o Rails (Олександр Сімонов)
 
Apikit from command line
Apikit from command lineApikit from command line
Apikit from command line
 
Web services with laravel
Web services with laravelWeb services with laravel
Web services with laravel
 
Be Happy With Ruby on Rails - Ecosystem
Be Happy With Ruby on Rails - EcosystemBe Happy With Ruby on Rails - Ecosystem
Be Happy With Ruby on Rails - Ecosystem
 
RoR 101: Session 3
RoR 101: Session 3RoR 101: Session 3
RoR 101: Session 3
 
Custom URL Re-Writing/Routing using Attribute Routes in MVC 4 Web APIs
Custom URL Re-Writing/Routing using Attribute Routes in MVC 4 Web APIsCustom URL Re-Writing/Routing using Attribute Routes in MVC 4 Web APIs
Custom URL Re-Writing/Routing using Attribute Routes in MVC 4 Web APIs
 
Rest api titouan benoit
Rest api   titouan benoitRest api   titouan benoit
Rest api titouan benoit
 
RoR 101: Session 2
RoR 101: Session 2RoR 101: Session 2
RoR 101: Session 2
 
Rack is Spectacular
Rack is SpectacularRack is Spectacular
Rack is Spectacular
 
Be happy with Ruby on Rails - CEUNSP Itu
Be happy with Ruby on Rails - CEUNSP ItuBe happy with Ruby on Rails - CEUNSP Itu
Be happy with Ruby on Rails - CEUNSP Itu
 

Similar to How to set up and test a Rails 3 Engine

Railties
RailtiesRailties
Railties
Skills Matter
 
Rails engine
Rails engineRails engine
Rails engine
Jyaasa Technologies
 
Ruby on Rails introduction
Ruby on Rails introduction Ruby on Rails introduction
Ruby on Rails introduction
Tran Hung
 
Introduction to Rails - presented by Arman Ortega
Introduction to Rails - presented by Arman OrtegaIntroduction to Rails - presented by Arman Ortega
Introduction to Rails - presented by Arman Ortega
arman o
 
TorqueBox - Ruby Hoedown 2011
TorqueBox - Ruby Hoedown 2011TorqueBox - Ruby Hoedown 2011
TorqueBox - Ruby Hoedown 2011
Lance Ball
 
Create a new project in ROR
Create a new project in RORCreate a new project in ROR
Create a new project in ROR
akankshita satapathy
 
.NET Architects Day - DNAD 2011
.NET Architects Day - DNAD 2011.NET Architects Day - DNAD 2011
.NET Architects Day - DNAD 2011
Fabio Akita
 
09 - Fábio Akita - Além do rails
09 - Fábio Akita - Além do rails09 - Fábio Akita - Além do rails
09 - Fábio Akita - Além do rails
DNAD
 
Rails request & middlewares
Rails request & middlewaresRails request & middlewares
Rails request & middlewares
Santosh Wadghule
 
Revised Rails Engine Patterns for Montreal.rb meetup Oct 16, 2012
Revised Rails Engine Patterns for Montreal.rb meetup Oct 16, 2012Revised Rails Engine Patterns for Montreal.rb meetup Oct 16, 2012
Revised Rails Engine Patterns for Montreal.rb meetup Oct 16, 2012Andy Maleh
 
TorqueBox
TorqueBoxTorqueBox
TorqueBox
bobmcwhirter
 
What's new and great in Rails 3 - Matt Gauger - Milwaukee Ruby Users Group De...
What's new and great in Rails 3 - Matt Gauger - Milwaukee Ruby Users Group De...What's new and great in Rails 3 - Matt Gauger - Milwaukee Ruby Users Group De...
What's new and great in Rails 3 - Matt Gauger - Milwaukee Ruby Users Group De...
Matt Gauger
 
Rails in the bowels
Rails in the bowelsRails in the bowels
Rails in the bowels
Creditas
 
Intro lift
Intro liftIntro lift
Intro lift
Knoldus Inc.
 
Service Oriented Applications
Service Oriented ApplicationsService Oriented Applications
Service Oriented Applications
Michael Bensoussan
 
A story about gemified engines
A story about gemified enginesA story about gemified engines
A story about gemified enginesmglrnm
 

Similar to How to set up and test a Rails 3 Engine (20)

Railties
RailtiesRailties
Railties
 
Rails engine
Rails engineRails engine
Rails engine
 
rails.html
rails.htmlrails.html
rails.html
 
rails.html
rails.htmlrails.html
rails.html
 
Ruby on Rails introduction
Ruby on Rails introduction Ruby on Rails introduction
Ruby on Rails introduction
 
Introduction to Rails - presented by Arman Ortega
Introduction to Rails - presented by Arman OrtegaIntroduction to Rails - presented by Arman Ortega
Introduction to Rails - presented by Arman Ortega
 
TorqueBox - Ruby Hoedown 2011
TorqueBox - Ruby Hoedown 2011TorqueBox - Ruby Hoedown 2011
TorqueBox - Ruby Hoedown 2011
 
Create a new project in ROR
Create a new project in RORCreate a new project in ROR
Create a new project in ROR
 
.NET Architects Day - DNAD 2011
.NET Architects Day - DNAD 2011.NET Architects Day - DNAD 2011
.NET Architects Day - DNAD 2011
 
09 - Fábio Akita - Além do rails
09 - Fábio Akita - Além do rails09 - Fábio Akita - Além do rails
09 - Fábio Akita - Além do rails
 
Rail3 intro 29th_sep_surendran
Rail3 intro 29th_sep_surendranRail3 intro 29th_sep_surendran
Rail3 intro 29th_sep_surendran
 
Rails request & middlewares
Rails request & middlewaresRails request & middlewares
Rails request & middlewares
 
Revised Rails Engine Patterns for Montreal.rb meetup Oct 16, 2012
Revised Rails Engine Patterns for Montreal.rb meetup Oct 16, 2012Revised Rails Engine Patterns for Montreal.rb meetup Oct 16, 2012
Revised Rails Engine Patterns for Montreal.rb meetup Oct 16, 2012
 
TorqueBox
TorqueBoxTorqueBox
TorqueBox
 
What's new and great in Rails 3 - Matt Gauger - Milwaukee Ruby Users Group De...
What's new and great in Rails 3 - Matt Gauger - Milwaukee Ruby Users Group De...What's new and great in Rails 3 - Matt Gauger - Milwaukee Ruby Users Group De...
What's new and great in Rails 3 - Matt Gauger - Milwaukee Ruby Users Group De...
 
Rails in the bowels
Rails in the bowelsRails in the bowels
Rails in the bowels
 
Intro lift
Intro liftIntro lift
Intro lift
 
Service Oriented Applications
Service Oriented ApplicationsService Oriented Applications
Service Oriented Applications
 
Intro to Rack
Intro to RackIntro to Rack
Intro to Rack
 
A story about gemified engines
A story about gemified enginesA story about gemified engines
A story about gemified engines
 

Recently uploaded

Connector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a buttonConnector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a button
DianaGray10
 
UiPath New York Community Day in-person event
UiPath New York Community Day in-person eventUiPath New York Community Day in-person event
UiPath New York Community Day in-person event
DianaGray10
 
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Product School
 
GraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge GraphGraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge Graph
Guy Korland
 
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Tobias Schneck
 
Knowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and backKnowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and back
Elena Simperl
 
НАДІЯ ФЕДЮШКО БАЦ «Професійне зростання QA спеціаліста»
НАДІЯ ФЕДЮШКО БАЦ  «Професійне зростання QA спеціаліста»НАДІЯ ФЕДЮШКО БАЦ  «Професійне зростання QA спеціаліста»
НАДІЯ ФЕДЮШКО БАЦ «Професійне зростання QA спеціаліста»
QADay
 
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdfFIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance
 
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered QualitySoftware Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Inflectra
 
Ransomware Mallox [EN].pdf
Ransomware         Mallox       [EN].pdfRansomware         Mallox       [EN].pdf
Ransomware Mallox [EN].pdf
Overkill Security
 
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Jeffrey Haguewood
 
Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........
Alison B. Lowndes
 
How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...
Product School
 
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
Product School
 
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Ramesh Iyer
 
Future Visions: Predictions to Guide and Time Tech Innovation, Peter Udo Diehl
Future Visions: Predictions to Guide and Time Tech Innovation, Peter Udo DiehlFuture Visions: Predictions to Guide and Time Tech Innovation, Peter Udo Diehl
Future Visions: Predictions to Guide and Time Tech Innovation, Peter Udo Diehl
Peter Udo Diehl
 
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Thierry Lestable
 
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
Product School
 
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdfFIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance
 
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 previewState of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
Prayukth K V
 

Recently uploaded (20)

Connector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a buttonConnector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a button
 
UiPath New York Community Day in-person event
UiPath New York Community Day in-person eventUiPath New York Community Day in-person event
UiPath New York Community Day in-person event
 
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
 
GraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge GraphGraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge Graph
 
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
 
Knowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and backKnowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and back
 
НАДІЯ ФЕДЮШКО БАЦ «Професійне зростання QA спеціаліста»
НАДІЯ ФЕДЮШКО БАЦ  «Професійне зростання QA спеціаліста»НАДІЯ ФЕДЮШКО БАЦ  «Професійне зростання QA спеціаліста»
НАДІЯ ФЕДЮШКО БАЦ «Професійне зростання QA спеціаліста»
 
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdfFIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
 
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered QualitySoftware Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
 
Ransomware Mallox [EN].pdf
Ransomware         Mallox       [EN].pdfRansomware         Mallox       [EN].pdf
Ransomware Mallox [EN].pdf
 
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
 
Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........
 
How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...
 
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
 
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
 
Future Visions: Predictions to Guide and Time Tech Innovation, Peter Udo Diehl
Future Visions: Predictions to Guide and Time Tech Innovation, Peter Udo DiehlFuture Visions: Predictions to Guide and Time Tech Innovation, Peter Udo Diehl
Future Visions: Predictions to Guide and Time Tech Innovation, Peter Udo Diehl
 
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
 
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
 
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdfFIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdf
 
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 previewState of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
 

How to set up and test a Rails 3 Engine

  • 1. HOW TO SETUP AND TEST RAILS 3 ENGINES. Nicholas Faiz, Tree Falling In The Woods, Pty Ltd.
  • 2. INTRO A quick introduction to Engines in Rails 3, including a demo of how to set one up and test it. Background: I've been working on a Rails 3 engine project since February or so. It might help if I share what I've encountered so far. Rails 3 Engines are new. Rails 3 RC 2 only released a few days ago.
  • 3. INTRO 2 Finding information on how to set up an Engine in Rails 3 has been difficult. Useful blogs: http:// www.themodestrubyist.com - by Jordan West. 4 posts about engines. Cesario: http://www.dev-fr.com/archives/ 2010/04/07/rails-3-railties-and-engines/
  • 4. STORY OF ENGINES SO FAR Engines before Rails 2.3 Engines Incorporated 2.3 Engines revamped in Rails 3
  • 5. STORY OF ENGINES ... 2 How were they revamped in Rails 3? Merb influence of decoupling. 2009 Merb merged with Rails. Merb influence r.e. decoupled dependencies! e.g. Should be able to use whichever ORM in your MVC. In Rails 3 engines revamped, now inherit from Rails::Railtie (See the Merb influence)
  • 6. WHAT ARE RAILTIES? Railties are a central concept to Rails 3. They decouple components from each other. See http://railsapi.com/doc/rails-v3.0.0.beta.3/ classes/Rails/Railtie.html All major aspects of the Rails Framework are now assembled into a larger system via a collection of Railties.
  • 7. WHAT ARE RAILTIES? 2 ActionController::Railtie < Rails::Railtie, ActionView::Railtie < Rails::Railtie, etc. Railties carry initializers, letting you configure how a Rails application is bootstrapped.’ initializer "configure something" {|app| config.something()}
  • 8. WHAT ARE ENGINES? Rails 3: Engines *are* Railties, well, subclasses of them. Rails::Engine < Rails::Railties In fact, every Rails application *is* an engine, well, a subclass ... Rails::Application < Rails::Engine
  • 9. WHAT ARE ENGINES? Only touching upon functionality in this presentation. Hosting applications can use them, or override them if they want to change things. Most known Rails 3 engine at the moment - Devise: http://github.com/plataformatec/devise
  • 10. CONFIGURE, BUNDLE, TEST Engines are a bit more than just a Rails application, though. More to it than the API. You have to know how to configure, bundle, and test it. You bundle a Rails engine, in its own gem, to reuse within another Rails application. First understand how an engine is accessed and used by a Rails application. Standard Rails app. paths available in the engine ...
  • 11. ENGINE PATHS class MyEngine < Rails::Engine paths.app = "app" paths.app.controllers = "app/controllers" paths.app.helpers = "app/helpers" paths.app.models = "app/models" paths.app.metals = "app/metal" paths.app.views = "app/views" paths.lib = "lib" paths.lib.tasks = "lib/tasks" paths.config = "config" paths.config.initializers = "config/initializers" paths.config.locales = "config/locales" paths.config.routes = "config/routes.rb" end
  • 12. ENGINES INSIDE THE HOST APP. All of this information is addressable via the Rails object. ruby-1.8.7-p299 > Rails.application.railties.engines Holds an array of engine objects.
  • 13. PATHS IN RAILS ENGINES rails console ruby-1.8.7-p299 > e = Rails.application.railties.engines.last ruby-1.8.7-p299 > e.config.paths.app a => #<Rails::Paths::Path:0x103bf7058 @eager_load=true, @root=#<Rails::Paths::Root: 0x103c02958 @all_paths=[#<Rails::Paths::Path:0x103bf7058 ...>, …, @paths=["app"]> ruby-1.8.7-p299 > e.class.name => "InklingContent::Engine" #helps to give your Railtie an informative namespace
  • 14. FINDING AN ENGINE BLUEPRINT I began working on my own engines and made headway in some areas but not others. I decided that I wanted a simple blueprint of how an engine should look. Because engines are new, there aren't established practices for setting them up and testing them. I've come up with my own, which seem like common sense, but took some thought.
  • 15. TOMMY THE RAILS 3 ENGINE! So I created Tommy, a simple application with a picture of Tommy the Tank engine repeating a message held in sqlite.
  • 16. HOW IS SOMETHING SO SIMPLE HELPFUL? Demonstrates some basic concepts. Some projects would actually copy their static files - javascripts, partials, etc. - *over* the hosting application. (e.g. BrowserCMS), in the Rails 2.x days. I needed to prove how sharing assets was done without this intrusion in Rails 3.
  • 17. IN DEMO LOOK FOR ... The Railties file (the engine). Generators for migrations. How to share static assets (like images, stylesheets, javascript files, etc.), from the engine into the host engine. How to share rake tasks. How to configure rspec and cucumber in an engine.
  • 18. TOMMY THE RAILS 3 ENGINE DEMO http://github.com/biv/tommy
  • 19. SUMMATION An engine can't be used without a functioning Rails app.. I find it easiest to nest a Rails app beneath the top directory. Tests for the engine can be created at the top level directory of the engine, but symlinked into the test app..
  • 20. SUMMATION 2 Rails 3 engines are new. I haven’t heard many stories, yet, about how they perform in production settings.
  • 21. CONTACT ME TO DISCUSS ENGINES I’m basing a lot of work in 2010/2011 on the Engine structure. I’m happy to discuss them: biv/brain_in_vat on #roro freenode http://twitter.com/nicholasf

Editor's Notes