O'Reilly logo

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Component-Based Rails Applications: Large Domains Under Control

Book Description

When Ruby on Rails was introduced, web developers flocked to it, quickly building applications that have become utterly indispensable to their organizations. But those early Rails applications have often proven extremely difficult to maintain, evolve, and scale. Now, in Component-Based Rails Applications, Stephan Hagemann introduces a practical, start-to-finish methodology for modernizing and restructuring existing Rails applications with modern components. One step at a time, Hagemann demonstrates how to revamp Rails applications to exhibit visible, provably independent, and explicitly connected parts--thereby simplifying them, and making them far easier to manage, change, and test.


The first and only guide to componentizing Rails, this book offers hands-on, step-by-step coverage of

  • Creating a full-fledged component-based Rails application from the ground up
  • Refactoring an existing Rails application to extract components
  • Using gems and engines to implement components in Ruby and Rails code bases
  • Applying modern patterns such as DCI and hexagonal architecture
  • Overcoming the unique challenges that arise during componentization of Rails applications

Throughout, Hagemann introduces concepts and techniques that developers can use to improve applications of many kinds, even if they weren’t built with Rails or Ruby.

Table of Contents

  1. Cover Page
  2. Title Page
  3. Contents
  4. Foreword
  5. Preface
    1. How I Came to Write This Book
    2. Who This Book Is For
    3. What This Book Does Not Cover
    4. How This Book Is Structured
  6. 1. Introduction to Component-Based Rails Applications
    1. 1.1 Component-Based Rails
    2. 1.2 Benefits of Component-Based Applications
    3. 1.3 Component-Based Ruby
    4. 1.4 The Application Continuum
    5. 1.5 Related Works
  7. 2. Creating a Component-based Application
    1. 2.1. The Entire App Inside of a Component
    2. 2.2. ActiveRecord and Handling Migrations Within Components
    3. 2.3. Handling Dependencies Within Components
  8. 3. Tooling for Components
    1. 3.1. Testing a Component
    2. 3.2. Testing the Main Application
    3. 3.3. Asset Loading for Components
    4. 3.4. Switching Databases
    5. 3.5. Deploying to Platforms-as-a-Service
    6. 3.6. Updating Application Dependencies
    7. 3.7. Proposal for a Different Application Root - Showcasing the Difference of Components’ Structure
  9. 4. Component Refactorings - Extracting Components out of Components
    1. 4.1. Determining What to Extract - Bottom-up
    2. 4.2. Refactoring: Extract Domain Gem - Predictor
    3. 4.3. Determining What to Extract - Top-down
    4. 4.4. Refactoring: Pulling Up a UI Component - TeamsAdmin, GamesAdmin, PredictionUI, WelcomeUI
    5. 4.5. Refactoring: Pushing Down a Model Component - Teams, Games
    6. 4.6. Refactoring: Improve Naming of Component - AppComponent to WebUI
    7. 4.7. More Component Refactoring Patterns
  10. 5. From Ball of Mud to First Components
    1. 5.1 Small Steps
    2. 5.2 One Big Step
  11. 6. Component-Based Rails in Relation to Other Patterns
    1. 6.1. Hexagonal Architecture
    2. 6.2. Data-Context-Integration (DCI)
  12. 7. Components in Other Languages
    1. 7.1 Kotlin, Java, and Gradle
    2. 7.2 .NET / C
    3. 7.3 Conclusion
  13. Appendix
    1. a. Plain versus --full versus --mountable Engines
    2. b. How do Engine Routes and Engine Mounting Work?
    3. c. Additional Testing With Older Versions of Rails