Layered Design for Ruby on Rails Applications: Discover practical design patterns for maintainable web applications

Layered Design for Ruby on Rails Applications: Discover practical design patterns for maintainable web applications

Layered Design for Ruby on Rails Applications: Discover practical design patterns for maintainable web applications
Автор: Dementyev Vladimir
Дата выхода: 2023
Издательство: Packt Publishing Limited
Количество страниц: 360
Размер файла: 1.9 MB
Тип файла: PDF
Добавил: codelibs
 Проверить на вирусы  Дополнительные материалы 

Cover Page....2

Table of Contents....3

Preface....4

Part 1: Exploring Rails and Its Abstractions....12

Chapter 1: Rails as a Web Application Framework....13

Technical requirements....13

The journey of a click through Rails abstraction layers....14

Beyond requests – background and scheduled tasks....26

The heart of a web application – the database....30

Summary....35

Questions....35

Exercises....36

Further reading....36

Chapter 2: Active Models and Records....37

Technical requirements....37

Active Record overview – persistence and beyond....38

Active Model – the hidden gem behind Active Record....49

Seeking God objects....58

Summary....60

Questions....61

Exercises....61

Further reading....61

Chapter 3: More Adapters, Less Implementations....63

Technical requirements....63

Active Job as a universal queue interface....64

Active Storage and its adapters and plugins....72

Adapters and wrappers at your service....77

Summary....80

Questions....81

Exercises....81

Further reading....81

Chapter 4: Rails Anti-Patterns?....82

Technical requirements....82

Callbacks, callbacks everywhere....83

Concerning Rails concerns....96

On global and current states....107

Summary....113

Questions....114

Exercises....114

Chapter 5: When Rails Abstractions Are Not Enough....115

Technical requirements....115

The curse of fat/thin controllers and thin/fat models....116

Generic services and granular abstractions....126

Layered architecture and abstraction layers....127

Summary....131

Questions....132

Part 2: Extracting Layers from Models....133

Chapter 6: Data Layer Abstractions....134

Technical requirements....134

Using query objects to extract (complex) queries from models....135

Separating domain and persistence with repositories....151

Summary....155

Questions....155

Chapter 7: Handling User Input outside of Models....157

Technical requirements....157

Form objects – closer to the UI, farther from persistence....158

Filter objects or user-driven query building....179

Summary....186

Questions....186

Exercise....187

Chapter 8: Pulling Out the Representation Layer....188

Technical requirements....188

Using presenters to decouple models from views....189

Serializers are presenters for your API....203

Summary....209

Questions....209

Further reading....210

Part 3: Essential Layers for Rails Applications....211

Chapter 9: Authorization Models and Layers....212

Technical requirements....212

Authorization, authentication, and friends....213

Authorization models....217

Authorization enforcement, or the need for authorization abstractions....223

Performance implications of authorization....236

Summary....240

Questions....240

Exercise....241

Further reading....241

Chapter 10: Crafting the Notifications Layer....242

Technical requirements....242

From Action Mailer to multiple notification channels....243

Extracting notifications layer....249

Modeling user notification preferences....260

Summary....265

Questions....265

Exercises....265

Chapter 11: Better Abstractions for HTML Views....267

Technical requirements....267

The V in Rails’ MVC: templates and helpers....267

Thinking in components....279

Summary....288

Questions....289

Further reading....289

Chapter 12: Configuration as a First-Class Application Citizen....290

Technical requirements....290

Configuration sources and types....291

Using domain objects to tame configuration complexity....299

Summary....311

Questions....312

Exercises....312

Chapter 13: Cross-Layers and Off-Layers....313

Technical requirements....313

The Rails infrastructure layer and its diversity....313

Across the layers – logging and monitoring....316

Extracting implementations into services....327

Summary....332

Questions....333

Index....334

Gems and Patterns....350

Why subscribe?....356

Other Books You May Enjoy....357

Packt is searching for authors like you....359

Share your thoughts....359

Download a free PDF copy of this book....360

Ruby on Rails is an open-source framework for building web applications from scratch while focusing on productivity, leveraging the power of the convention-over-configuration principle, and the well-defined model-view-controller pattern, assisting the developers in building useful features. However, this initial simplicity often leads to uncontrollable complexity turning the well-structured codebase into a hardly maintainable mess. This book aims to help you keep the code maintainable while working on a Rails application.

You’ll start by exploring the framework capabilities and principles, allowing you to reap the full potential of Rails. Then, you’ll tackle many common design problems by discovering useful patterns and abstraction layers. By implementing abstraction and dividing the application into manageable modules, you’ll be able to concentrate on specific parts of the app development without getting overwhelmed by the entire codebase. This strategy also encourages code reuse, simplifying the process of adding new features and enhancing the application's capabilities. Additionally, you’ll explore further steps in scaling Rails codebase, such as service extractions.

By the end of this book, you’ll be a code design specialist with a deep understanding of the Rails framework principles.

What you will learn

  • Discover Rails' core components and its request/response cycle
  • Understand Rails' convention-over-configuration principle and its impact on development
  • Explore patterns for flexibility, extensibility, and testability in Rails
  • Identify and address Rails’ anti-patterns for cleaner code
  • Implement design patterns for handling bloated models and messy views
  • Expand from mailers to multi-channel notification deliveries
  • Explore different authorization models and layers
  • Use a class-based approach to configuration in Rails

Who this book is for

This book is for Rails application developers facing challenges in managing the growing complexity of their projects. It offers practical strategies for maintaining code readability and manageability, providing valuable guidance for developers at all levels. Whether you've recently launched your first Rails minimum viable product or are struggling to progress with a sizable monolithic application, this book is here to help. A deep understanding of core Rails principles is a must. Some experience in building web applications using the Rails framework will enhance your comprehension and application of the concepts presented in the book.


Похожее:

Список отзывов:

Нет отзывов к книге.