Architecting Multiple Ruby on Rails Applications that Share a - - PowerPoint PPT Presentation

architecting multiple ruby on rails applications that
SMART_READER_LITE
LIVE PREVIEW

Architecting Multiple Ruby on Rails Applications that Share a - - PowerPoint PPT Presentation

Architecting Multiple Ruby on Rails Applications that Share a Common Code Base NOVA Software Architecture Roundtable Gregory Hodum - ghodum@solutionstreet.com Business Problem Client wants you to build another RoR application that is similar


slide-1
SLIDE 1

Architecting Multiple Ruby

  • n Rails Applications that

Share a Common Code Base

NOVA Software Architecture Roundtable Gregory Hodum - ghodum@solutionstreet.com

slide-2
SLIDE 2

Business Problem

Client wants you to build another RoR application that is similar to the one you just developed…

slide-3
SLIDE 3

Business Problem

…but different…

slide-4
SLIDE 4

Architecture Goals

  • Share common functionality
  • Ideally the full MVC stack
  • Ability to easily customize/extend common

functionality

  • Minimize maintenance
  • Encourage DRY principle
slide-5
SLIDE 5

Solutions?

  • All-in-one app
  • Expose common functionality as separate services communicating

via API

  • REST, WS, etc.
  • Code level organization
  • Re-usable software component(s)
  • Ruby gem, Rails Engine
  • Separate code repositories/projects
  • Others solutions? Thoughts?
slide-6
SLIDE 6

We decided to use Rails Engines

slide-7
SLIDE 7

Rails Engines

Ruby gem + MVC stack elements

http://guides.rubyonrails.org/engines.html

slide-8
SLIDE 8
  • Rails Engines let applications reuse:
  • Models / Views / Controllers / Helpers
  • Assets (JS, CSS, Images)
  • Routes
  • Rake tasks
  • Generators
  • Initializers
  • Tests
  • Migrations and seed data Libraries
slide-9
SLIDE 9

blorgh

Rails Engine

rainbow

Rails App

unicorn

Rails App

slide-10
SLIDE 10

Extending Engine Functionality

  • Overriding/Extending Models and Controllers
  • Open classing using concerns (Rails

ActiveSupport::Concern)

  • Override Views
  • Looks in application first, then Engine
slide-11
SLIDE 11

Real World Rails Engines

  • Devise - A flexible authentication solution for Rails
  • https://github.com/plataformatec/devise
  • Forem - engine for Rails that aims to be the best little forum system ever
  • https://github.com/radar/forem
  • Spree - A complete open source e-commerce solution for Ruby on Rails
  • https://github.com/spree/spree
  • RefineryCMS - An open source content management system for Rails
  • https://github.com/refinery/refinerycms
slide-12
SLIDE 12

To generate a new Rails Engine: rails plugin new blorgh --mountable

slide-13
SLIDE 13

Then include as a gem in your application’s Gemfile: gem 'blorgh', path: "/path/to/blorgh"

slide-14
SLIDE 14

Let’s see the code…

slide-15
SLIDE 15

Converting an existing app to use Rails Engines so far…

  • Engine Module/Name-spacing
  • Be careful with table names, relations, existing app code references to

Engine classes

  • Refactor common classes into Concerns in the Engine
  • Include filesystem reference to Engine gem during development
  • Pull specific versions from git during CI/Test/Deployment builds
  • Angular UI/Assets
  • Have not tackled this layer yet, another topic for another time
  • Testing
  • Standalone tests (RSpec) for the Engine, validates Engine functionality
  • App test coverage needs to include Engine functionality that has been
  • verridden/extended
slide-16
SLIDE 16

Questions?

Additional Thoughts?

slide-17
SLIDE 17

References

  • Code from this presentation:
  • https://github.com/ghodum/blorgh
  • https://github.com/ghodum/unicorn
  • http://guides.rubyonrails.org/engines.html
  • http://www.slideshare.net/AndyMaleh/rails-engine-patterns
  • http://hawkins.io/2012/03/defining_plugins_gems_railties_and_engines/
  • http://blog.pivotal.io/pivotal-labs/labs/migrating-from-a-single-rails-app-to-a-

suite-of-rails-engines#pitfalls

  • http://www.toptal.com/ruby-on-rails/rails-engines-in-the-wild-real-world-

examples-of-rails-engines-in-action