architecting multiple ruby on rails applications that
play

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


  1. Architecting Multiple Ruby on Rails Applications that Share a Common Code Base NOVA Software Architecture Roundtable Gregory Hodum - ghodum@solutionstreet.com

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

  3. Business Problem …but different…

  4. Architecture Goals • Share common functionality • Ideally the full MVC stack • Ability to easily customize/extend common functionality • Minimize maintenance • Encourage DRY principle

  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?

  6. We decided to use Rails Engines

  7. Rails Engines Ruby gem + MVC stack elements http://guides.rubyonrails.org/engines.html

  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

  9. blorgh Rails Engine rainbow unicorn Rails App Rails App

  10. Extending Engine Functionality • Overriding/Extending Models and Controllers • Open classing using concerns (Rails ActiveSupport::Concern) • Override Views • Looks in application first, then Engine

  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

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

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

  14. Let’s see the code…

  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 • overridden/extended

  16. Questions? Additional Thoughts?

  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

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend