SlideShare a Scribd company logo
Problem
 Difficulty reusing functionality cutting across:
   Models
   Views
   Controllers
   Assets (JS, CSS, Images)
 Duplication across all web application layers.
Courtesy of © 2002-2011 National Collegiate Scouting Association - All Rights Reserved
Solution
 Break common behavior into Rails Engines

 Customize models/controllers/helpers in each
 project where needed by reopening classes

 Customize Rails views in each project as needed
 by overriding templates

 Link to Rails Engines in Gemfile via Git repo
Example
                     Common
                     Domain
                       Rails Engine



          Search Map
             Rails Engine


  High School         Public           Athlete
   Recruiting        Profiles         Recruiting
      Rails App         Rails App        Rails App
Courtesy of © 2002-2011 National Collegiate Scouting Association - All Rights Reserved
Courtesy of © 2002-2011 National Collegiate Scouting Association - All Rights Reserved
Overview
 Engines let applications reuse:
   Models / Views / Controllers / Helpers
   Assets (JS, CSS, Images)
   Routes
   Rake tasks
   Initializers
   RSpec / Cucumber
   More (migrations, seeds, libraries)
Engine Definition
 An engine structure is similar to a Rails app
 having app, config, lib, spec, features, etc…
 lib/engine_name.rb (read online instructions)
 lib/engine_name/engine.rb (read online
 instructions)
 To reuse engine, use “jeweler” gem to generate
 gemspec (read online instructions)
lib/engine_name.rb
lib/engine_name/engine.rb
Engine Consumption
    Reference engine via Gemfile as a Ruby gem or
    Git repo hosted gemified project:




Courtesy of © 2002-2011 National Collegiate Scouting Association - All Rights Reserved
Load Order
 Typically Rails app files load first before Engine
 files.

 Strongly recommended to reverse (by patching
 “active_support/dependencies.rb”) so that
 engine’s Ruby code is overrideable in app (see
 next slide)

 ERB files can be overridden in Rails app
Ruby Code Customization
 Model/Helper/Controller behavior can be
 customized be redefining .rb files in Rails app:
   Add new methods/behavior
   Replace existing methods
   Extend existing methods via alias_method_chain
View Customization
 View files (erb, haml, etc…) and Asset files (js,
 css, and images) can be redefined in Rails app to
 override completely for customization purposes
Code Examples
Typical Development
Process
1. Make changes in engine, rake, and commit
   obtaining a new git ref
2. Update Gemfile in app with new git ref, run
   “bundle install” (getting ride of symlink)
3. Rake and commit changes in app.
4. If more changes in engine are needed go back
   to step 1
Improved Productivity via
Symlinking
 Multiple engine dependencies can hamper
 productivity when frequently going back and
 forth between engines and app
 Engines gems installed via bundler can be
 symlinked to allow continuous development until
 done with both app and
 engine:http://andymaleh.blogspot.com/2011/09/
 more-productive-rails-engine.html
Improved Development
Process
1. Open Rails app and symlink all engines “rake
   engine:symlink[engine_name]”
2. Work in app and engine until done WITHOUT running
   “bundle install”
3. Rake and commit changes in engine obtaining a new git
   ref
4. Update Gemfile in app with git ref, run “bundle install”
   (getting ride of symlink)
5. Rake and commit changes in app
Engines Reuse Engines
 Rails engines can reuse other Rails engines

 When multiple levels of depth are involved (e.g.
 App => Engine 1 => Engine 2), commit repos and
 update Gemfile from the bottom up (e.g. Engine
 2 => Engine 1 => App)
Engine Configuration
 Engines can be configured to customize rack
 middleware, load paths, generators, and Rails
 component paths. More details at:
 http://edgeapi.rubyonrails.org/classes/Rails/Engi
 ne.html
Isolated Engines
 To avoid Ruby namespace clash with
 Models/Helpers/Controllers, you can define an
 isolated namespaced engine:
Rails Engine Patterns
 Goals:
  Keep engine code agnostic of app customizations
  Prevent bi-directional coupling to simplify
  reasoning about code
  Avoid app dependent conditionals to improve code
  maintainability
Pattern - Common Domain
 Problem: Multiple applications need to share a
 basic domain model but want to customize
 behavior without mixing concerns across apps
 Solution:
  In engine, please basic domain model definitions
  and common associations only
  In each app, define specialized behavior and extra
  associations for domain models
Pattern - Expose Helper
 Problem: need to customize presentation logic
 for a view in one app only, but keep the same
 logic in others
 Solution:
  In engine, extract helper logic that needs
  customization into its own helper.
  In app, redefine that new helper with
  customizations.
Pattern - Expose Partial
 Problem: need to customize a part of the view in
 one app only, but keep it the same in others

 Solution:
  In engine, extract view part that needs
  customization as a partial.
  In app, redefine that partial with customizations.
Pattern - Extension Partial
 Problem: One app needs to add content to a
 view that is not needed in other apps
 Solution:
  In engine, introduce a new partial with empty
  contents in area that needs extension for the one
  app.
  In app, define that partial with the required
  content.
Pattern - Extension Partial



                                                             SIDEBAR
                                                             Extension
                                                              Partial



     Courtesy of © 2011 Groupon, Inc. All Rights Reserved.
Pattern - Extension Point
 Problem: different apps need to contribute data to a
 view in different places (e.g. contribute
 columns/rows in different spots)
 Solution:
   In engine, add logic that looks up partials in a specific
   ext directory, and based on file name (e.g.
   row_7.html.erb), determine index on where to insert it in
   the view.
   In app, define these partials with the right file names
   and locations.
Pattern - Extension Point

1

2

3


4

5
Pattern - Configurable
Features
 Problem: different apps need different features from
 an engine in different combinations
 Solution:
   In engine, add logic that looks up configuration options
   from a constant hash (e.g. ENGINE_XYZ_CONFIG =
   {:header => “visible”, :footer => “visible”, …}).
   In app, configure engine by overriding configuration
   options (e.g. ENGINE_XYZ_CONFIG[:header] =
   “hidden”)
Rails Engine Benefits
 Code reuse across all application layers

 Better maintainability due to:
   Independent project codebases
   Cleanly defined boundaries between projects and
   reusable components (engines)
 Project tests get smaller and run faster
Rails Engine Costs
 Overhead in establishing a new Rails Engine
 gem project

 Continuous switching between projects and
 engines to get work done

 Upgrade of ref numbers in Gemfile on every
 commit (minimized with symlinking)
More Info
 http://edgeapi.rubyonrails.org/classes/Rails/Engi
 ne.html

 http://andymaleh.blogspot.com/2011/09/more-
 productive-rails-engine.html

 http://stackoverflow.com/questions/2964050/rail
 s-engines-extending-
 functionality/2990539#2990539
Contact
 Andy Maleh
  Code Painter Blog http://andymaleh.blogspot.com
  Twitter: @AndyMaleh

More Related Content

What's hot

Eclipse - Single Source;Three Runtimes
Eclipse - Single Source;Three RuntimesEclipse - Single Source;Three Runtimes
Eclipse - Single Source;Three Runtimes
Suresh Krishna Madhuvarsu
 
Getting Started with SharePoint 2013 Apps
Getting Started with SharePoint 2013 AppsGetting Started with SharePoint 2013 Apps
Getting Started with SharePoint 2013 Apps
Randy Williams
 
1 z0 543-q&a-demo-examarea
1 z0 543-q&a-demo-examarea1 z0 543-q&a-demo-examarea
1 z0 543-q&a-demo-examarea
SamanthaGreen16
 
RAML - The architecture
RAML  - The architectureRAML  - The architecture
RAML - The architecture
Ankush Sharma
 
Hyperion planning what you should know
Hyperion planning what you should knowHyperion planning what you should know
Hyperion planning what you should know
Amit Sharma
 
Angular Routing Tutorial | AngularJS vs Angular Router | Angular Training | E...
Angular Routing Tutorial | AngularJS vs Angular Router | Angular Training | E...Angular Routing Tutorial | AngularJS vs Angular Router | Angular Training | E...
Angular Routing Tutorial | AngularJS vs Angular Router | Angular Training | E...
Edureka!
 
The API Facade Pattern: Common Patterns - Episode 2
The API Facade Pattern: Common Patterns - Episode 2The API Facade Pattern: Common Patterns - Episode 2
The API Facade Pattern: Common Patterns - Episode 2
Apigee | Google Cloud
 
Anypoint access management - Roles
Anypoint access management - RolesAnypoint access management - Roles
Anypoint access management - Roles
Shanky Gupta
 
Plugin architecture (Extensible Application Architecture)
Plugin architecture (Extensible Application Architecture)Plugin architecture (Extensible Application Architecture)
Plugin architecture (Extensible Application Architecture)
Chinmoy Mohanty
 
RAML
RAMLRAML
Meet AWS SAM
Meet AWS SAMMeet AWS SAM
Meet AWS SAM
Eric Johnson
 
Design API using RAML - basics
Design API using RAML - basicsDesign API using RAML - basics
Design API using RAML - basics
kunal vishe
 
Adobe Ask the AEM Community Expert Session Oct 2016
Adobe Ask the AEM Community Expert Session Oct 2016Adobe Ask the AEM Community Expert Session Oct 2016
Adobe Ask the AEM Community Expert Session Oct 2016
AdobeMarketingCloud
 
Anypoint access management
Anypoint access management Anypoint access management
Anypoint access management
Shanky Gupta
 
Rest With Raml
Rest With RamlRest With Raml
Rest With Raml
vijay dhanakodi
 
eRCP Overview and Update '06
eRCP Overview  and Update '06eRCP Overview  and Update '06
eRCP Overview and Update '06
Gorkem Ercan
 
Continuous Integration and Continuous Delivery for your serverless apps - Seb...
Continuous Integration and Continuous Delivery for your serverless apps - Seb...Continuous Integration and Continuous Delivery for your serverless apps - Seb...
Continuous Integration and Continuous Delivery for your serverless apps - Seb...
Shift Conference
 
Create Location Sharing apps using the Ionic framework
Create Location Sharing apps using the Ionic framework					Create Location Sharing apps using the Ionic framework
Create Location Sharing apps using the Ionic framework
Shelly Megan
 
REST API Doc Best Practices
REST API Doc Best PracticesREST API Doc Best Practices
REST API Doc Best Practices
Marta Rauch
 
Quickly Build a Native Mobile App for Your Community Using Salesforce Mobile SDK
Quickly Build a Native Mobile App for Your Community Using Salesforce Mobile SDKQuickly Build a Native Mobile App for Your Community Using Salesforce Mobile SDK
Quickly Build a Native Mobile App for Your Community Using Salesforce Mobile SDK
Salesforce Developers
 

What's hot (20)

Eclipse - Single Source;Three Runtimes
Eclipse - Single Source;Three RuntimesEclipse - Single Source;Three Runtimes
Eclipse - Single Source;Three Runtimes
 
Getting Started with SharePoint 2013 Apps
Getting Started with SharePoint 2013 AppsGetting Started with SharePoint 2013 Apps
Getting Started with SharePoint 2013 Apps
 
1 z0 543-q&a-demo-examarea
1 z0 543-q&a-demo-examarea1 z0 543-q&a-demo-examarea
1 z0 543-q&a-demo-examarea
 
RAML - The architecture
RAML  - The architectureRAML  - The architecture
RAML - The architecture
 
Hyperion planning what you should know
Hyperion planning what you should knowHyperion planning what you should know
Hyperion planning what you should know
 
Angular Routing Tutorial | AngularJS vs Angular Router | Angular Training | E...
Angular Routing Tutorial | AngularJS vs Angular Router | Angular Training | E...Angular Routing Tutorial | AngularJS vs Angular Router | Angular Training | E...
Angular Routing Tutorial | AngularJS vs Angular Router | Angular Training | E...
 
The API Facade Pattern: Common Patterns - Episode 2
The API Facade Pattern: Common Patterns - Episode 2The API Facade Pattern: Common Patterns - Episode 2
The API Facade Pattern: Common Patterns - Episode 2
 
Anypoint access management - Roles
Anypoint access management - RolesAnypoint access management - Roles
Anypoint access management - Roles
 
Plugin architecture (Extensible Application Architecture)
Plugin architecture (Extensible Application Architecture)Plugin architecture (Extensible Application Architecture)
Plugin architecture (Extensible Application Architecture)
 
RAML
RAMLRAML
RAML
 
Meet AWS SAM
Meet AWS SAMMeet AWS SAM
Meet AWS SAM
 
Design API using RAML - basics
Design API using RAML - basicsDesign API using RAML - basics
Design API using RAML - basics
 
Adobe Ask the AEM Community Expert Session Oct 2016
Adobe Ask the AEM Community Expert Session Oct 2016Adobe Ask the AEM Community Expert Session Oct 2016
Adobe Ask the AEM Community Expert Session Oct 2016
 
Anypoint access management
Anypoint access management Anypoint access management
Anypoint access management
 
Rest With Raml
Rest With RamlRest With Raml
Rest With Raml
 
eRCP Overview and Update '06
eRCP Overview  and Update '06eRCP Overview  and Update '06
eRCP Overview and Update '06
 
Continuous Integration and Continuous Delivery for your serverless apps - Seb...
Continuous Integration and Continuous Delivery for your serverless apps - Seb...Continuous Integration and Continuous Delivery for your serverless apps - Seb...
Continuous Integration and Continuous Delivery for your serverless apps - Seb...
 
Create Location Sharing apps using the Ionic framework
Create Location Sharing apps using the Ionic framework					Create Location Sharing apps using the Ionic framework
Create Location Sharing apps using the Ionic framework
 
REST API Doc Best Practices
REST API Doc Best PracticesREST API Doc Best Practices
REST API Doc Best Practices
 
Quickly Build a Native Mobile App for Your Community Using Salesforce Mobile SDK
Quickly Build a Native Mobile App for Your Community Using Salesforce Mobile SDKQuickly Build a Native Mobile App for Your Community Using Salesforce Mobile SDK
Quickly Build a Native Mobile App for Your Community Using Salesforce Mobile SDK
 

Similar to The Rails Engine That Could - In Motion

The Rails Engine That Could
The Rails Engine That CouldThe Rails Engine That Could
The Rails Engine That Could
Andy Maleh
 
Rails review
Rails reviewRails review
Rails review
Alan Hecht
 
Rails engines
Rails enginesRails engines
Rails engines
Josh Schramm
 
Strategies and Tips for Building Enterprise Drupal Applications - PNWDS 2013
Strategies and Tips for Building Enterprise Drupal Applications - PNWDS 2013Strategies and Tips for Building Enterprise Drupal Applications - PNWDS 2013
Strategies and Tips for Building Enterprise Drupal Applications - PNWDS 2013
Mack Hardy
 
Angular2 and You
Angular2 and YouAngular2 and You
Angular2 and You
Joseph Jorden
 
Understanding angular js
Understanding angular jsUnderstanding angular js
Understanding angular js
Aayush Shrestha
 
Pluggable patterns
Pluggable patternsPluggable patterns
Pluggable patterns
Corey Oordt
 
Rails engine
Rails engineRails engine
Rails engine
Jyaasa Technologies
 
Backbonification for dummies - Arrrrug 10/1/2012
Backbonification for dummies - Arrrrug 10/1/2012Backbonification for dummies - Arrrrug 10/1/2012
Backbonification for dummies - Arrrrug 10/1/2012
Dimitri de Putte
 
SPA Editor - Adobe Experience Manager Sites
SPA Editor - Adobe Experience Manager SitesSPA Editor - Adobe Experience Manager Sites
SPA Editor - Adobe Experience Manager Sites
Gabriel Walt
 
Oleg Bogut - Decoupled Drupal: how to build stable solution with JSON:API, Re...
Oleg Bogut - Decoupled Drupal: how to build stable solution with JSON:API, Re...Oleg Bogut - Decoupled Drupal: how to build stable solution with JSON:API, Re...
Oleg Bogut - Decoupled Drupal: how to build stable solution with JSON:API, Re...
DrupalCamp Kyiv
 
Introduction To Angular.js - SpringPeople
Introduction To Angular.js - SpringPeopleIntroduction To Angular.js - SpringPeople
Introduction To Angular.js - SpringPeople
SpringPeople
 
Vue3: nuove funzionalità, differenze e come migrare
Vue3: nuove funzionalità, differenze e come migrareVue3: nuove funzionalità, differenze e come migrare
Vue3: nuove funzionalità, differenze e come migrare
Andrea Campaci
 
Adobe Experience Manager Core Components
Adobe Experience Manager Core ComponentsAdobe Experience Manager Core Components
Adobe Experience Manager Core Components
Gabriel Walt
 
Reactjs notes.pptx for web development- tutorial and theory
Reactjs  notes.pptx for web development- tutorial and theoryReactjs  notes.pptx for web development- tutorial and theory
Reactjs notes.pptx for web development- tutorial and theory
jobinThomas54
 
Fame
FameFame
Fame
rpatil82
 
App Engine On Air: Munich
App Engine On Air: MunichApp Engine On Air: Munich
App Engine On Air: Munich
dion
 
Top 10 Javascript Frameworks For Easy Web Development
Top 10 Javascript Frameworks For Easy Web DevelopmentTop 10 Javascript Frameworks For Easy Web Development
Top 10 Javascript Frameworks For Easy Web Development
Technostacks Infotech Pvt. Ltd.
 
Metamorphosis from Forms to Java: A technical lead's perspective, part II
Metamorphosis from Forms to Java:  A technical lead's perspective, part IIMetamorphosis from Forms to Java:  A technical lead's perspective, part II
Metamorphosis from Forms to Java: A technical lead's perspective, part II
Michael Fons
 
Angularjs2 presentation
Angularjs2 presentationAngularjs2 presentation
Angularjs2 presentation
dharisk
 

Similar to The Rails Engine That Could - In Motion (20)

The Rails Engine That Could
The Rails Engine That CouldThe Rails Engine That Could
The Rails Engine That Could
 
Rails review
Rails reviewRails review
Rails review
 
Rails engines
Rails enginesRails engines
Rails engines
 
Strategies and Tips for Building Enterprise Drupal Applications - PNWDS 2013
Strategies and Tips for Building Enterprise Drupal Applications - PNWDS 2013Strategies and Tips for Building Enterprise Drupal Applications - PNWDS 2013
Strategies and Tips for Building Enterprise Drupal Applications - PNWDS 2013
 
Angular2 and You
Angular2 and YouAngular2 and You
Angular2 and You
 
Understanding angular js
Understanding angular jsUnderstanding angular js
Understanding angular js
 
Pluggable patterns
Pluggable patternsPluggable patterns
Pluggable patterns
 
Rails engine
Rails engineRails engine
Rails engine
 
Backbonification for dummies - Arrrrug 10/1/2012
Backbonification for dummies - Arrrrug 10/1/2012Backbonification for dummies - Arrrrug 10/1/2012
Backbonification for dummies - Arrrrug 10/1/2012
 
SPA Editor - Adobe Experience Manager Sites
SPA Editor - Adobe Experience Manager SitesSPA Editor - Adobe Experience Manager Sites
SPA Editor - Adobe Experience Manager Sites
 
Oleg Bogut - Decoupled Drupal: how to build stable solution with JSON:API, Re...
Oleg Bogut - Decoupled Drupal: how to build stable solution with JSON:API, Re...Oleg Bogut - Decoupled Drupal: how to build stable solution with JSON:API, Re...
Oleg Bogut - Decoupled Drupal: how to build stable solution with JSON:API, Re...
 
Introduction To Angular.js - SpringPeople
Introduction To Angular.js - SpringPeopleIntroduction To Angular.js - SpringPeople
Introduction To Angular.js - SpringPeople
 
Vue3: nuove funzionalità, differenze e come migrare
Vue3: nuove funzionalità, differenze e come migrareVue3: nuove funzionalità, differenze e come migrare
Vue3: nuove funzionalità, differenze e come migrare
 
Adobe Experience Manager Core Components
Adobe Experience Manager Core ComponentsAdobe Experience Manager Core Components
Adobe Experience Manager Core Components
 
Reactjs notes.pptx for web development- tutorial and theory
Reactjs  notes.pptx for web development- tutorial and theoryReactjs  notes.pptx for web development- tutorial and theory
Reactjs notes.pptx for web development- tutorial and theory
 
Fame
FameFame
Fame
 
App Engine On Air: Munich
App Engine On Air: MunichApp Engine On Air: Munich
App Engine On Air: Munich
 
Top 10 Javascript Frameworks For Easy Web Development
Top 10 Javascript Frameworks For Easy Web DevelopmentTop 10 Javascript Frameworks For Easy Web Development
Top 10 Javascript Frameworks For Easy Web Development
 
Metamorphosis from Forms to Java: A technical lead's perspective, part II
Metamorphosis from Forms to Java:  A technical lead's perspective, part IIMetamorphosis from Forms to Java:  A technical lead's perspective, part II
Metamorphosis from Forms to Java: A technical lead's perspective, part II
 
Angularjs2 presentation
Angularjs2 presentationAngularjs2 presentation
Angularjs2 presentation
 

More from Andy Maleh

Fukuoka Ruby Award 2023 - Opal
Fukuoka Ruby Award 2023 - OpalFukuoka Ruby Award 2023 - Opal
Fukuoka Ruby Award 2023 - Opal
Andy Maleh
 
Becoming a SOC2 Ruby Shop - Montreal.rb November, 5, 2022 Ruby Meetup
Becoming a SOC2 Ruby Shop - Montreal.rb November, 5, 2022 Ruby MeetupBecoming a SOC2 Ruby Shop - Montreal.rb November, 5, 2022 Ruby Meetup
Becoming a SOC2 Ruby Shop - Montreal.rb November, 5, 2022 Ruby Meetup
Andy Maleh
 
Montreal.rb 2022-10-05 - Glimmer DSL for SWT - Ruby Desktop Development GUI ...
 Montreal.rb 2022-10-05 - Glimmer DSL for SWT - Ruby Desktop Development GUI ... Montreal.rb 2022-10-05 - Glimmer DSL for SWT - Ruby Desktop Development GUI ...
Montreal.rb 2022-10-05 - Glimmer DSL for SWT - Ruby Desktop Development GUI ...
Andy Maleh
 
How I Built My Code Editor in Ruby
How I Built My Code Editor in RubyHow I Built My Code Editor in Ruby
How I Built My Code Editor in Ruby
Andy Maleh
 
Ultra Light and Maintainable Rails Wizards at RailsConf 2014
Ultra Light and Maintainable Rails Wizards at RailsConf 2014Ultra Light and Maintainable Rails Wizards at RailsConf 2014
Ultra Light and Maintainable Rails Wizards at RailsConf 2014
Andy Maleh
 
RailsConf 2014 Recap at Montreal.rb by Andy Maleh
RailsConf 2014 Recap at Montreal.rb by Andy MalehRailsConf 2014 Recap at Montreal.rb by Andy Maleh
RailsConf 2014 Recap at Montreal.rb by Andy Maleh
Andy Maleh
 
Ultra Light and Maintainable Wizards in Rails at Montreal.rb
Ultra Light and Maintainable Wizards in Rails at Montreal.rbUltra Light and Maintainable Wizards in Rails at Montreal.rb
Ultra Light and Maintainable Wizards in Rails at Montreal.rb
Andy Maleh
 
Software Craftsmanship VS Software Engineering
Software Craftsmanship VS Software EngineeringSoftware Craftsmanship VS Software Engineering
Software Craftsmanship VS Software Engineering
Andy Maleh
 
Software Craftsmanship vs Software Engineering (Lightning Talk)
Software Craftsmanship vs Software Engineering (Lightning Talk)Software Craftsmanship vs Software Engineering (Lightning Talk)
Software Craftsmanship vs Software Engineering (Lightning Talk)
Andy Maleh
 
Software Design Trilogy Part III - Domain Driven Design for Ruby on Rails App...
Software Design Trilogy Part III - Domain Driven Design for Ruby on Rails App...Software Design Trilogy Part III - Domain Driven Design for Ruby on Rails App...
Software Design Trilogy Part III - Domain Driven Design for Ruby on Rails App...
Andy Maleh
 
Software Design Trilogy Part II - Design Patterns for Rubyists
Software Design Trilogy Part II - Design Patterns for RubyistsSoftware Design Trilogy Part II - Design Patterns for Rubyists
Software Design Trilogy Part II - Design Patterns for Rubyists
Andy Maleh
 
Software Design Trilogy Part I - Responsibility Driven Design for Rubyists
Software Design Trilogy Part I - Responsibility Driven Design for RubyistsSoftware Design Trilogy Part I - Responsibility Driven Design for Rubyists
Software Design Trilogy Part I - Responsibility Driven Design for Rubyists
Andy Maleh
 
How I Learned To Apply Design Patterns
How I Learned To Apply Design PatternsHow I Learned To Apply Design Patterns
How I Learned To Apply Design Patterns
Andy Maleh
 
Simplifying Desktop Development With Glimmer
Simplifying Desktop Development With GlimmerSimplifying Desktop Development With Glimmer
Simplifying Desktop Development With Glimmer
Andy Maleh
 

More from Andy Maleh (14)

Fukuoka Ruby Award 2023 - Opal
Fukuoka Ruby Award 2023 - OpalFukuoka Ruby Award 2023 - Opal
Fukuoka Ruby Award 2023 - Opal
 
Becoming a SOC2 Ruby Shop - Montreal.rb November, 5, 2022 Ruby Meetup
Becoming a SOC2 Ruby Shop - Montreal.rb November, 5, 2022 Ruby MeetupBecoming a SOC2 Ruby Shop - Montreal.rb November, 5, 2022 Ruby Meetup
Becoming a SOC2 Ruby Shop - Montreal.rb November, 5, 2022 Ruby Meetup
 
Montreal.rb 2022-10-05 - Glimmer DSL for SWT - Ruby Desktop Development GUI ...
 Montreal.rb 2022-10-05 - Glimmer DSL for SWT - Ruby Desktop Development GUI ... Montreal.rb 2022-10-05 - Glimmer DSL for SWT - Ruby Desktop Development GUI ...
Montreal.rb 2022-10-05 - Glimmer DSL for SWT - Ruby Desktop Development GUI ...
 
How I Built My Code Editor in Ruby
How I Built My Code Editor in RubyHow I Built My Code Editor in Ruby
How I Built My Code Editor in Ruby
 
Ultra Light and Maintainable Rails Wizards at RailsConf 2014
Ultra Light and Maintainable Rails Wizards at RailsConf 2014Ultra Light and Maintainable Rails Wizards at RailsConf 2014
Ultra Light and Maintainable Rails Wizards at RailsConf 2014
 
RailsConf 2014 Recap at Montreal.rb by Andy Maleh
RailsConf 2014 Recap at Montreal.rb by Andy MalehRailsConf 2014 Recap at Montreal.rb by Andy Maleh
RailsConf 2014 Recap at Montreal.rb by Andy Maleh
 
Ultra Light and Maintainable Wizards in Rails at Montreal.rb
Ultra Light and Maintainable Wizards in Rails at Montreal.rbUltra Light and Maintainable Wizards in Rails at Montreal.rb
Ultra Light and Maintainable Wizards in Rails at Montreal.rb
 
Software Craftsmanship VS Software Engineering
Software Craftsmanship VS Software EngineeringSoftware Craftsmanship VS Software Engineering
Software Craftsmanship VS Software Engineering
 
Software Craftsmanship vs Software Engineering (Lightning Talk)
Software Craftsmanship vs Software Engineering (Lightning Talk)Software Craftsmanship vs Software Engineering (Lightning Talk)
Software Craftsmanship vs Software Engineering (Lightning Talk)
 
Software Design Trilogy Part III - Domain Driven Design for Ruby on Rails App...
Software Design Trilogy Part III - Domain Driven Design for Ruby on Rails App...Software Design Trilogy Part III - Domain Driven Design for Ruby on Rails App...
Software Design Trilogy Part III - Domain Driven Design for Ruby on Rails App...
 
Software Design Trilogy Part II - Design Patterns for Rubyists
Software Design Trilogy Part II - Design Patterns for RubyistsSoftware Design Trilogy Part II - Design Patterns for Rubyists
Software Design Trilogy Part II - Design Patterns for Rubyists
 
Software Design Trilogy Part I - Responsibility Driven Design for Rubyists
Software Design Trilogy Part I - Responsibility Driven Design for RubyistsSoftware Design Trilogy Part I - Responsibility Driven Design for Rubyists
Software Design Trilogy Part I - Responsibility Driven Design for Rubyists
 
How I Learned To Apply Design Patterns
How I Learned To Apply Design PatternsHow I Learned To Apply Design Patterns
How I Learned To Apply Design Patterns
 
Simplifying Desktop Development With Glimmer
Simplifying Desktop Development With GlimmerSimplifying Desktop Development With Glimmer
Simplifying Desktop Development With Glimmer
 

Recently uploaded

HCL Notes and Domino License Cost Reduction in the World of DLAU
HCL Notes and Domino License Cost Reduction in the World of DLAUHCL Notes and Domino License Cost Reduction in the World of DLAU
HCL Notes and Domino License Cost Reduction in the World of DLAU
panagenda
 
Serial Arm Control in Real Time Presentation
Serial Arm Control in Real Time PresentationSerial Arm Control in Real Time Presentation
Serial Arm Control in Real Time Presentation
tolgahangng
 
Astute Business Solutions | Oracle Cloud Partner |
Astute Business Solutions | Oracle Cloud Partner |Astute Business Solutions | Oracle Cloud Partner |
Astute Business Solutions | Oracle Cloud Partner |
AstuteBusiness
 
Public CyberSecurity Awareness Presentation 2024.pptx
Public CyberSecurity Awareness Presentation 2024.pptxPublic CyberSecurity Awareness Presentation 2024.pptx
Public CyberSecurity Awareness Presentation 2024.pptx
marufrahmanstratejm
 
System Design Case Study: Building a Scalable E-Commerce Platform - Hiike
System Design Case Study: Building a Scalable E-Commerce Platform - HiikeSystem Design Case Study: Building a Scalable E-Commerce Platform - Hiike
System Design Case Study: Building a Scalable E-Commerce Platform - Hiike
Hiike
 
TrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy SurveyTrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy Survey
TrustArc
 
GraphRAG for Life Science to increase LLM accuracy
GraphRAG for Life Science to increase LLM accuracyGraphRAG for Life Science to increase LLM accuracy
GraphRAG for Life Science to increase LLM accuracy
Tomaz Bratanic
 
Trusted Execution Environment for Decentralized Process Mining
Trusted Execution Environment for Decentralized Process MiningTrusted Execution Environment for Decentralized Process Mining
Trusted Execution Environment for Decentralized Process Mining
LucaBarbaro3
 
Introduction of Cybersecurity with OSS at Code Europe 2024
Introduction of Cybersecurity with OSS  at Code Europe 2024Introduction of Cybersecurity with OSS  at Code Europe 2024
Introduction of Cybersecurity with OSS at Code Europe 2024
Hiroshi SHIBATA
 
JavaLand 2024: Application Development Green Masterplan
JavaLand 2024: Application Development Green MasterplanJavaLand 2024: Application Development Green Masterplan
JavaLand 2024: Application Development Green Masterplan
Miro Wengner
 
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with SlackLet's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
shyamraj55
 
Building Production Ready Search Pipelines with Spark and Milvus
Building Production Ready Search Pipelines with Spark and MilvusBuilding Production Ready Search Pipelines with Spark and Milvus
Building Production Ready Search Pipelines with Spark and Milvus
Zilliz
 
Driving Business Innovation: Latest Generative AI Advancements & Success Story
Driving Business Innovation: Latest Generative AI Advancements & Success StoryDriving Business Innovation: Latest Generative AI Advancements & Success Story
Driving Business Innovation: Latest Generative AI Advancements & Success Story
Safe Software
 
Choosing The Best AWS Service For Your Website + API.pptx
Choosing The Best AWS Service For Your Website + API.pptxChoosing The Best AWS Service For Your Website + API.pptx
Choosing The Best AWS Service For Your Website + API.pptx
Brandon Minnick, MBA
 
Presentation of the OECD Artificial Intelligence Review of Germany
Presentation of the OECD Artificial Intelligence Review of GermanyPresentation of the OECD Artificial Intelligence Review of Germany
Presentation of the OECD Artificial Intelligence Review of Germany
innovationoecd
 
5th LF Energy Power Grid Model Meet-up Slides
5th LF Energy Power Grid Model Meet-up Slides5th LF Energy Power Grid Model Meet-up Slides
5th LF Energy Power Grid Model Meet-up Slides
DanBrown980551
 
AWS Cloud Cost Optimization Presentation.pptx
AWS Cloud Cost Optimization Presentation.pptxAWS Cloud Cost Optimization Presentation.pptx
AWS Cloud Cost Optimization Presentation.pptx
HarisZaheer8
 
Azure API Management to expose backend services securely
Azure API Management to expose backend services securelyAzure API Management to expose backend services securely
Azure API Management to expose backend services securely
Dinusha Kumarasiri
 
Main news related to the CCS TSI 2023 (2023/1695)
Main news related to the CCS TSI 2023 (2023/1695)Main news related to the CCS TSI 2023 (2023/1695)
Main news related to the CCS TSI 2023 (2023/1695)
Jakub Marek
 
GNSS spoofing via SDR (Criptored Talks 2024)
GNSS spoofing via SDR (Criptored Talks 2024)GNSS spoofing via SDR (Criptored Talks 2024)
GNSS spoofing via SDR (Criptored Talks 2024)
Javier Junquera
 

Recently uploaded (20)

HCL Notes and Domino License Cost Reduction in the World of DLAU
HCL Notes and Domino License Cost Reduction in the World of DLAUHCL Notes and Domino License Cost Reduction in the World of DLAU
HCL Notes and Domino License Cost Reduction in the World of DLAU
 
Serial Arm Control in Real Time Presentation
Serial Arm Control in Real Time PresentationSerial Arm Control in Real Time Presentation
Serial Arm Control in Real Time Presentation
 
Astute Business Solutions | Oracle Cloud Partner |
Astute Business Solutions | Oracle Cloud Partner |Astute Business Solutions | Oracle Cloud Partner |
Astute Business Solutions | Oracle Cloud Partner |
 
Public CyberSecurity Awareness Presentation 2024.pptx
Public CyberSecurity Awareness Presentation 2024.pptxPublic CyberSecurity Awareness Presentation 2024.pptx
Public CyberSecurity Awareness Presentation 2024.pptx
 
System Design Case Study: Building a Scalable E-Commerce Platform - Hiike
System Design Case Study: Building a Scalable E-Commerce Platform - HiikeSystem Design Case Study: Building a Scalable E-Commerce Platform - Hiike
System Design Case Study: Building a Scalable E-Commerce Platform - Hiike
 
TrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy SurveyTrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy Survey
 
GraphRAG for Life Science to increase LLM accuracy
GraphRAG for Life Science to increase LLM accuracyGraphRAG for Life Science to increase LLM accuracy
GraphRAG for Life Science to increase LLM accuracy
 
Trusted Execution Environment for Decentralized Process Mining
Trusted Execution Environment for Decentralized Process MiningTrusted Execution Environment for Decentralized Process Mining
Trusted Execution Environment for Decentralized Process Mining
 
Introduction of Cybersecurity with OSS at Code Europe 2024
Introduction of Cybersecurity with OSS  at Code Europe 2024Introduction of Cybersecurity with OSS  at Code Europe 2024
Introduction of Cybersecurity with OSS at Code Europe 2024
 
JavaLand 2024: Application Development Green Masterplan
JavaLand 2024: Application Development Green MasterplanJavaLand 2024: Application Development Green Masterplan
JavaLand 2024: Application Development Green Masterplan
 
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with SlackLet's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
 
Building Production Ready Search Pipelines with Spark and Milvus
Building Production Ready Search Pipelines with Spark and MilvusBuilding Production Ready Search Pipelines with Spark and Milvus
Building Production Ready Search Pipelines with Spark and Milvus
 
Driving Business Innovation: Latest Generative AI Advancements & Success Story
Driving Business Innovation: Latest Generative AI Advancements & Success StoryDriving Business Innovation: Latest Generative AI Advancements & Success Story
Driving Business Innovation: Latest Generative AI Advancements & Success Story
 
Choosing The Best AWS Service For Your Website + API.pptx
Choosing The Best AWS Service For Your Website + API.pptxChoosing The Best AWS Service For Your Website + API.pptx
Choosing The Best AWS Service For Your Website + API.pptx
 
Presentation of the OECD Artificial Intelligence Review of Germany
Presentation of the OECD Artificial Intelligence Review of GermanyPresentation of the OECD Artificial Intelligence Review of Germany
Presentation of the OECD Artificial Intelligence Review of Germany
 
5th LF Energy Power Grid Model Meet-up Slides
5th LF Energy Power Grid Model Meet-up Slides5th LF Energy Power Grid Model Meet-up Slides
5th LF Energy Power Grid Model Meet-up Slides
 
AWS Cloud Cost Optimization Presentation.pptx
AWS Cloud Cost Optimization Presentation.pptxAWS Cloud Cost Optimization Presentation.pptx
AWS Cloud Cost Optimization Presentation.pptx
 
Azure API Management to expose backend services securely
Azure API Management to expose backend services securelyAzure API Management to expose backend services securely
Azure API Management to expose backend services securely
 
Main news related to the CCS TSI 2023 (2023/1695)
Main news related to the CCS TSI 2023 (2023/1695)Main news related to the CCS TSI 2023 (2023/1695)
Main news related to the CCS TSI 2023 (2023/1695)
 
GNSS spoofing via SDR (Criptored Talks 2024)
GNSS spoofing via SDR (Criptored Talks 2024)GNSS spoofing via SDR (Criptored Talks 2024)
GNSS spoofing via SDR (Criptored Talks 2024)
 

The Rails Engine That Could - In Motion

  • 1.
  • 2. Problem Difficulty reusing functionality cutting across: Models Views Controllers Assets (JS, CSS, Images) Duplication across all web application layers.
  • 3. Courtesy of © 2002-2011 National Collegiate Scouting Association - All Rights Reserved
  • 4. Solution Break common behavior into Rails Engines Customize models/controllers/helpers in each project where needed by reopening classes Customize Rails views in each project as needed by overriding templates Link to Rails Engines in Gemfile via Git repo
  • 5. Example Common Domain Rails Engine Search Map Rails Engine High School Public Athlete Recruiting Profiles Recruiting Rails App Rails App Rails App
  • 6. Courtesy of © 2002-2011 National Collegiate Scouting Association - All Rights Reserved
  • 7. Courtesy of © 2002-2011 National Collegiate Scouting Association - All Rights Reserved
  • 8. Overview Engines let applications reuse: Models / Views / Controllers / Helpers Assets (JS, CSS, Images) Routes Rake tasks Initializers RSpec / Cucumber More (migrations, seeds, libraries)
  • 9. Engine Definition An engine structure is similar to a Rails app having app, config, lib, spec, features, etc… lib/engine_name.rb (read online instructions) lib/engine_name/engine.rb (read online instructions) To reuse engine, use “jeweler” gem to generate gemspec (read online instructions)
  • 12. Engine Consumption Reference engine via Gemfile as a Ruby gem or Git repo hosted gemified project: Courtesy of © 2002-2011 National Collegiate Scouting Association - All Rights Reserved
  • 13. Load Order Typically Rails app files load first before Engine files. Strongly recommended to reverse (by patching “active_support/dependencies.rb”) so that engine’s Ruby code is overrideable in app (see next slide) ERB files can be overridden in Rails app
  • 14.
  • 15. Ruby Code Customization Model/Helper/Controller behavior can be customized be redefining .rb files in Rails app: Add new methods/behavior Replace existing methods Extend existing methods via alias_method_chain
  • 16. View Customization View files (erb, haml, etc…) and Asset files (js, css, and images) can be redefined in Rails app to override completely for customization purposes
  • 18. Typical Development Process 1. Make changes in engine, rake, and commit obtaining a new git ref 2. Update Gemfile in app with new git ref, run “bundle install” (getting ride of symlink) 3. Rake and commit changes in app. 4. If more changes in engine are needed go back to step 1
  • 19. Improved Productivity via Symlinking Multiple engine dependencies can hamper productivity when frequently going back and forth between engines and app Engines gems installed via bundler can be symlinked to allow continuous development until done with both app and engine:http://andymaleh.blogspot.com/2011/09/ more-productive-rails-engine.html
  • 20. Improved Development Process 1. Open Rails app and symlink all engines “rake engine:symlink[engine_name]” 2. Work in app and engine until done WITHOUT running “bundle install” 3. Rake and commit changes in engine obtaining a new git ref 4. Update Gemfile in app with git ref, run “bundle install” (getting ride of symlink) 5. Rake and commit changes in app
  • 21. Engines Reuse Engines Rails engines can reuse other Rails engines When multiple levels of depth are involved (e.g. App => Engine 1 => Engine 2), commit repos and update Gemfile from the bottom up (e.g. Engine 2 => Engine 1 => App)
  • 22. Engine Configuration Engines can be configured to customize rack middleware, load paths, generators, and Rails component paths. More details at: http://edgeapi.rubyonrails.org/classes/Rails/Engi ne.html
  • 23. Isolated Engines To avoid Ruby namespace clash with Models/Helpers/Controllers, you can define an isolated namespaced engine:
  • 24. Rails Engine Patterns Goals: Keep engine code agnostic of app customizations Prevent bi-directional coupling to simplify reasoning about code Avoid app dependent conditionals to improve code maintainability
  • 25. Pattern - Common Domain Problem: Multiple applications need to share a basic domain model but want to customize behavior without mixing concerns across apps Solution: In engine, please basic domain model definitions and common associations only In each app, define specialized behavior and extra associations for domain models
  • 26. Pattern - Expose Helper Problem: need to customize presentation logic for a view in one app only, but keep the same logic in others Solution: In engine, extract helper logic that needs customization into its own helper. In app, redefine that new helper with customizations.
  • 27. Pattern - Expose Partial Problem: need to customize a part of the view in one app only, but keep it the same in others Solution: In engine, extract view part that needs customization as a partial. In app, redefine that partial with customizations.
  • 28. Pattern - Extension Partial Problem: One app needs to add content to a view that is not needed in other apps Solution: In engine, introduce a new partial with empty contents in area that needs extension for the one app. In app, define that partial with the required content.
  • 29. Pattern - Extension Partial SIDEBAR Extension Partial Courtesy of © 2011 Groupon, Inc. All Rights Reserved.
  • 30. Pattern - Extension Point Problem: different apps need to contribute data to a view in different places (e.g. contribute columns/rows in different spots) Solution: In engine, add logic that looks up partials in a specific ext directory, and based on file name (e.g. row_7.html.erb), determine index on where to insert it in the view. In app, define these partials with the right file names and locations.
  • 31. Pattern - Extension Point 1 2 3 4 5
  • 32. Pattern - Configurable Features Problem: different apps need different features from an engine in different combinations Solution: In engine, add logic that looks up configuration options from a constant hash (e.g. ENGINE_XYZ_CONFIG = {:header => “visible”, :footer => “visible”, …}). In app, configure engine by overriding configuration options (e.g. ENGINE_XYZ_CONFIG[:header] = “hidden”)
  • 33. Rails Engine Benefits Code reuse across all application layers Better maintainability due to: Independent project codebases Cleanly defined boundaries between projects and reusable components (engines) Project tests get smaller and run faster
  • 34. Rails Engine Costs Overhead in establishing a new Rails Engine gem project Continuous switching between projects and engines to get work done Upgrade of ref numbers in Gemfile on every commit (minimized with symlinking)
  • 35. More Info http://edgeapi.rubyonrails.org/classes/Rails/Engi ne.html http://andymaleh.blogspot.com/2011/09/more- productive-rails-engine.html http://stackoverflow.com/questions/2964050/rail s-engines-extending- functionality/2990539#2990539
  • 36. Contact Andy Maleh Code Painter Blog http://andymaleh.blogspot.com Twitter: @AndyMaleh