|
1 | 1 | # ActiveRecordCompose |
2 | 2 |
|
3 | 3 | ActiveRecordCompose lets you build form objects that combine multiple ActiveRecord models into a single, unified interface. |
4 | | -More than just a simple form object, it is designed as a **business-oriented composed model** that encapsulates complex operations-such as user registration spanning multiple tables-making them easier to write, validate, and maintain. |
| 4 | +More than a simple form object, ActiveRecordCompose is designed as a **business-oriented composed model** that encapsulates complex operations, such as user registration spanning multiple tables, making them easier to write, validate, and maintain. |
5 | 5 |
|
6 | 6 | [](https://badge.fury.io/rb/active_record_compose) |
7 | 7 |  |
@@ -29,15 +29,14 @@ More than just a simple form object, it is designed as a **business-oriented com |
29 | 29 |
|
30 | 30 | ## Motivation |
31 | 31 |
|
32 | | -In Rails, `ActiveRecord::Base` is responsible for persisting data to the database. |
33 | | -By defining validations and callbacks, you can model use cases effectively. |
| 32 | +In Rails, `ActiveRecord::Base` is responsible for persisting data to the database and modeling application behavior through validations and callbacks. |
34 | 33 |
|
35 | 34 | However, when a single model must serve multiple different use cases, you often end up with conditional validations (`on: :context`) or workarounds like `save(validate: false)`. |
36 | 35 | This mixes unrelated concerns into one model, leading to unnecessary complexity. |
37 | 36 |
|
38 | | -`ActiveModel::Model` helps here — it provides the familiar API (`attribute`, `errors`, validations, callbacks) without persistence, so you can isolate logic per use case. |
| 37 | +`ActiveModel::Model` helps address this by providing a familiar API (`attribute`, `errors`, validations, callbacks) without persistence, allowing you to isolate logic per use case. |
39 | 38 |
|
40 | | -**ActiveRecordCompose** builds on `ActiveModel::Model` and is a powerful **business object** that acts as a first-class model within Rails. |
| 39 | +**ActiveRecordCompose** builds on `ActiveModel::Model` and provides a powerful **business object** that acts as a first-class model within Rails. |
41 | 40 | - Transparently accesses attributes across multiple models |
42 | 41 | - Saves all associated models atomically in a transaction |
43 | 42 | - Collects and exposes error information consistently |
@@ -106,7 +105,7 @@ class UserRegistration < ActiveRecordCompose::Model |
106 | 105 | end |
107 | 106 | ``` |
108 | 107 |
|
109 | | -Usage: |
| 108 | +Example usage: |
110 | 109 |
|
111 | 110 | ```ruby |
112 | 111 | # === Standalone script === |
@@ -174,7 +173,7 @@ registration.attributes |
174 | 173 |
|
175 | 174 | ### Unified Error Handling |
176 | 175 |
|
177 | | -Validation errors from inner models are collected into the composed model: |
| 176 | +Validation errors from the inner models are collected into the composed object: |
178 | 177 |
|
179 | 178 | ```ruby |
180 | 179 | user_registration = UserRegistration.new( |
@@ -274,7 +273,7 @@ model.save |
274 | 273 |
|
275 | 274 | ### Notes on adding models dynamically |
276 | 275 |
|
277 | | -Avoid adding `models` to the models array **after validation has already run** |
| 276 | +Avoid adding models to the `models` array **after validation has already run** |
278 | 277 | (for example, inside `after_validation` or `before_save` callbacks). |
279 | 278 |
|
280 | 279 | ```ruby |
@@ -323,5 +322,5 @@ The gem is available as open source under the terms of the [MIT License](https:/ |
323 | 322 |
|
324 | 323 | ## Code of Conduct |
325 | 324 |
|
326 | | -Everyone interacting in the ActiveRecord::Compose project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/hamajyotan/active_record_compose/blob/main/CODE_OF_CONDUCT.md). |
| 325 | +Everyone interacting in the ActiveRecordCompose project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/hamajyotan/active_record_compose/blob/main/CODE_OF_CONDUCT.md). |
327 | 326 |
|
0 commit comments