Component-Based Rails Applications: Large Domains Under Control

Book description

Use Components to Improve Maintainability, Reduce Complexity, and Accelerate Testing in Large Rails Applications

“This book gives Ruby pros a comprehensive guide for increasing the sophistication of their designs, without having to forsake the principles of elegance that keep them in our corner of the software world.”

–Obie Fernandez, author, The Rails™ 5 Way, Fourth Edition

As Rails applications grow, even experienced developers find it difficult to navigate code bases, implement new features, and keep tests fast. Components are the solution, and Component-Based Rails Applications shows how to make the most of them.

Writing for programmers and software team leads who are comfortable with Ruby and Rails, Stephan Hagemann introduces a practical, start-to-finish methodology for modernizing and restructuring existing Rails applications.

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 for teams to manage, change, and test. Throughout, he introduces design concepts and techniques you can use to improve applications of many kinds, even if they weren’t built with Rails or Ruby.

  • Learn how components clarify intent, improve collaboration, and simplify innovation and maintenance
  • Create a full Rails application within a component, from first steps to migrations and dependency management
  • Test component-based applications, manage assets and dependencies, and deploy your application to production
  • Identify the seams in an existing Rails application, and refactor it to extract components
  • Master a scripted, repeatable approach for refactoring Rails applications of any size
  • Use component-based Rails with two popular structural patterns: hexagonal and DCI architecture
  • Leverage your new component skills with other frameworks and languages
  • Overcome the unique challenges that arise as you componentize Rails applications

If you’re ready to simplify and revitalize your complex Rails systems, you’re ready for Component-Based Rails Applications.

Register your book for convenient access to downloads, updates, and/or corrections as they become available. See inside book for details.

Table of contents

  1. Cover Page
  2. Title Page
  3. Copyright Page
  4. Contents
  5. About This E-Book
  6. Foreword
  7. Preface
  8. Acknowledgments
  9. About the Author
  10. Dedication
  11. Chapter 1 Introduction to Component-Based Rails Applications
    1. 1.1 Component-Based Rails
      1. 1.1.1 What Component-Based Rails Is
    2. 1.2 Benefits of Component-Based Applications
      1. 1.2.1 Improved Communication of Intent
      2. 1.2.2 Improved Collaboration Among Developers
      3. 1.2.3 Improved Creation of Features
      4. 1.2.4 Improved Maintenance of the Application
      5. 1.2.5 Improved Comprehension of Application Parts
      6. 1.2.6 History Repeating?
    3. 1.3 Component-Based Ruby
    4. 1.4 The Application Continuum
    5. 1.5 Related Works
  12. Chapter 2 Creating a Component-Based Application
    1. 2.1 The Entire App Inside a Component
    2. 2.2 ActiveRecord and Handling Migrations within Components
      1. 2.2.1 Installing Engine Migrations with Rake
      2. 2.2.2 Loading Engine Migrations in Place
      3. 2.2.3 Known Issues
    3. 2.3 Handling Dependencies within Components
      1. 2.3.1 Using path Blocks for Specifying CBRA Dependencies
      2. 2.3.2 Adding a Regular Gem: slim—Different Templating
      3. 2.3.3 Locking Down Gem Versions
      4. 2.3.4 Adding the Development Version of a Gem: Trueskill—A Rating Calculation Library
      5. 2.3.5 Adding Predictions to the App
  13. Chapter 3 Tooling for Components
    1. 3.1 Testing a Component
      1. 3.1.1 ActiveRecord Model Specs
      2. 3.1.2 Non-ActiveRecord Model Specs
      3. 3.1.3 Controller Specs
      4. 3.1.4 Helper Specs
      5. 3.1.5 Feature Specs
    2. 3.2 Testing the Main Application
      1. 3.2.1 What to Test in the Main App
      2. 3.2.2 How to Put Everything Together
      3. 3.2.3 How to Set Up a Continuous Integration (CI) Server
    3. 3.3 Asset Loading for Components
      1. 3.3.1 Production-Ready Assets
    4. 3.4 Switching Databases
    5. 3.5 Deploying to Platforms-as-a-Service
      1. 3.5.1 Deploying to Heroku
      2. 3.5.2 Deploying to Pivotal Web Services
    6. 3.6 Updating Application Dependencies
      1. 3.6.1 Updating the Bundle in All Components
      2. 3.6.2 Updating Every Component’s Gem Version
      3. 3.6.3 Updating Rails
      4. 3.6.4 Long-Running Dependency Updates
      5. 3.6.5 Listing a Dependency Only Once
    7. 3.7 Proposal for a Different Application Root—Showcasing the Difference of Components’ Structure
      1. 3.7.1 Why Would I Want to Change That?
      2. 3.7.2 How CBRA Can Change How I Present and Perceive My App
      3. 3.7.3 Making CI and PaaS Work with the New Structure
      4. 3.7.4 What Is Next?
  14. Chapter 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
      1. 4.2.1 Fixing Inside-Out: Making AppComponent Work Again
      2. 4.2.2 Last Step: Ensure That the App Works
      3. 4.2.3 Summary of Bottom-Up Component Extractions
    3. 4.3 Determining What to Extract: Top-Down
      1. 4.3.1 Unclear Dependency Direction
      2. 4.3.2 Not Everything Needs Predictor
      3. 4.3.3 Implications of the First Set of Extractions
      4. 4.3.4 Problem with the Current Solution
      5. 4.3.5 Reducing Needed Dependencies
    4. 4.4 Refactoring: Pulling Up a UI Component—TeamsAdmin, GamesAdmin, PredictionUI, WelcomeUI
      1. 4.4.1 Generate
      2. 4.4.2 Move
      3. 4.4.3 Fix, Part 1: Reusing Test Helpers
      4. 4.4.4 Fix, Part 2: Routing Issues
      5. 4.4.5 Fix, Part 3: The Container Application
      6. 4.4.6 An Explicitly Contracted Global Navigation
    5. 4.5 Refactoring: Pushing Down a Model Component—Teams, Games
      1. 4.5.1 Getting Away with Less
      2. 4.5.2 Fixing Teams Tests
      3. 4.5.3 Fixing Everything Else
    6. 4.6 Refactoring: Improve Naming of Component—AppComponent to WebUI
      1. 4.6.1 Whatever Happened to AppComponent?
      2. 4.6.2 Refactoring Component Names
      3. 4.6.3 Refactoring a Component Name Throughout the Application
      4. 4.6.4 An Even More Mechanical Approach
    7. 4.7 More Component Refactoring Patterns
      1. 4.7.1 Splitting One Component in Two: Disentangling Unrelated Concepts
      2. 4.7.2 API Component
      3. 4.7.3 Third-Party Service Adapter
      4. 4.7.4 Common Functionality Component
  15. Chapter 5 From Ball of Mud to First Components
    1. 5.1 Small Steps
    2. 5.2 One Big Step
      1. 5.2.1 Prerequisites
      2. 5.2.2 Script This!
      3. 5.2.3 A Scripted Refactoring
      4. 5.2.4 Cleaning Up Persistence
      5. 5.2.5 Using Persistence
      6. 5.2.6 Summary
  16. Chapter 6 Component-Based Rails in Relation to Other Patterns
    1. 6.1 Hexagonal Architecture
      1. 6.1.1 Hexagonal Architecture and CBRA
      2. 6.1.2 Implementing Hexagonal Rails with CBRA
      3. 6.1.3 Teasing Out an Adapter in the Frontend
      4. 6.1.4 A Repository for Data Storage
      5. 6.1.5 Swappable Data Storage
      6. 6.1.6 Summary
    2. 6.2 Data-Context-Integration (DCI)
      1. 6.2.1 DCI and CBRA
      2. 6.2.2 Implementing DCI with CBRA
      3. 6.2.3 Summary
  17. Chapter 7 Components in Other Languages
    1. 7.1 Kotlin, Java, and Gradle
    2. 7.2 .NET / C
    3. 7.3 Conclusion
  18. Appendix
    1. A.1 Plain versus --full versus --mountable Engines
      1. A.1.1 Gem
      2. A.1.2 Plain Plugin
      3. A.1.3 Full Engine
      4. A.1.4 Mountable Engine
    2. A.2 How Do Engine Routes and Engine Mounting Work?
      1. A.2.1 Engines as Subdomains
      2. A.2.2 Engines Are (Unfortunately) Singletons
    3. A.3 Additional Testing with Older Versions of Rails
      1. A.3.1 View Specs
      2. A.3.2 Routing Specs
  19. Index
  20. Code Snippets

Product information

  • Title: Component-Based Rails Applications: Large Domains Under Control
  • Author(s): Stephan Hagemann
  • Release date: June 2018
  • Publisher(s): Addison-Wesley Professional
  • ISBN: 9780134775241