Skip to content

Commit 6509305

Browse files
committed
Merge pull request #1310 from maurogeorge/patch-12
RFC: Primary namespace: ActiveModel::Serializer, ActiveModel::Serializers, vs. ActiveModelSerializers
2 parents 58ff753 + 2f8c430 commit 6509305

File tree

1 file changed

+106
-0
lines changed

1 file changed

+106
-0
lines changed

docs/rfcs/0000-namespace.md

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
- Start Date: (2015-10-29)
2+
- RFC PR: https://github.com/rails-api/active_model_serializers/pull/1310
3+
- ActiveModelSerializers Issue: https://github.com/rails-api/active_model_serializers/issues/1298
4+
5+
# Summary
6+
7+
Provide a consistent API for the user of the AMS.
8+
9+
# Motivation
10+
11+
The actual public API is defined under `ActiveModelSerializers`,
12+
`ActiveModel::Serializer` and `ActiveModel`.
13+
14+
At the `ActiveModel::Serializer` we have:
15+
16+
- `ActiveModel::Serializer.config`
17+
- `ActiveModel::Serializer`
18+
19+
At the `ActiveModelSerializers` we have:
20+
21+
- `ActiveModelSerializers::Model`
22+
- `ActiveModelSerializers.logger`
23+
24+
At `ActiveModel` we have:
25+
26+
- `ActiveModel::SerializableResource`
27+
28+
The idea here is to provide a single namespace `ActiveModelSerializers` to the user.
29+
Following the same idea we have on other gems like
30+
[Devise](https://github.com/plataformatec/devise/blob/e9c82472ffe7c43a448945f77e034a0e47dde0bb/lib/devise.rb),
31+
[Refile](https://github.com/refile/refile/blob/6b24c293d044862dafbf1bfa4606672a64903aa2/lib/refile.rb) and
32+
[Active Job](https://github.com/rails/rails/blob/30bacc26f8f258b39e12f63fe52389a968d9c1ea/activejob/lib/active_job.rb)
33+
for example.
34+
35+
This way we are clarifing the boundaries of
36+
[ActiveModelSerializers and Rails](https://github.com/rails-api/active_model_serializers/blob/master/CHANGELOG.md#prehistory)
37+
and make clear that the `ActiveModel::Serializer` class is no longer the primary
38+
behavior of the ActiveModelSerializers.
39+
40+
# Detailed design
41+
42+
## New classes and modules organization
43+
44+
Since this will be a big change we can do this on baby steps, read small pull requests. A
45+
possible approach is:
46+
47+
- All new code will be in `lib/active_model_serializers/` using
48+
the module namespace `ActiveModelSerializers`.
49+
- Move all content under `ActiveModel::Serializer` to be under
50+
`ActiveModelSerializers`, the adapter is on this steps;
51+
- Move all content under `ActiveModel` to be under `ActiveModelSerializers`,
52+
the `SerializableResource` is on this step;
53+
- Change all public API that doesn't make sense, keeping in mind only to keep
54+
this in the same namespace
55+
- Update the README;
56+
- Update the docs;
57+
58+
The following table represents the current and the desired classes and modules
59+
at the first moment.
60+
61+
| Current | Desired | Notes |
62+
|--------------------------------------------------------|--------------------------------------------------|--------------------|
63+
| `ActiveModelSerializers` and `ActiveModel::Serializer` | `ActiveModelSerializers` | The main namespace |
64+
| `ActiveModelSerializers.logger` | `ActiveModelSerializers.logger` ||
65+
| `ActiveModelSerializers::Model` | `ActiveModelSerializers::Model` ||
66+
| `ActiveModel::SerializableResource` | `ActiveModelSerializers::SerializableResource` ||
67+
| `ActiveModel::Serializer` | `ActiveModelSerializers::Serializer` | The name can be discussed in a future pull request. For example, we can rename this to `Resource` [following this idea](https://github.com/rails-api/active_model_serializers/pull/1301/files#r42963185) more info about naming in the next section|
68+
| `ActiveModel::Serializer.config` | `ActiveModelSerializers.config` ||
69+
70+
## Renaming of class and modules
71+
72+
When moving some content to the new namespace we can find some names that does
73+
not make much sense like `ActiveModelSerializers::Serializer::Adapter::JsonApi`.
74+
Discussion of renaming existing classes / modules and JsonApi objects will
75+
happen in separate pull requests, and issues, and in the google doc
76+
https://docs.google.com/document/d/1rcrJr0sVcazY2Opd_6Kmv1iIwuHbI84s1P_NzFn-05c/edit?usp=sharing
77+
78+
Some of names already have a definition.
79+
80+
- Adapters get their own namespace under ActiveModelSerializers. E.g
81+
`ActiveModelSerializers::Adapter`
82+
- Serializers get their own namespace under ActiveModelSerializers. E.g
83+
`ActiveModelSerializers::Serializer`
84+
85+
## Keeping compatibility
86+
87+
All moved classes or modules be aliased to their old name and location with
88+
deprecation warnings, such as
89+
[was done for CollectionSerializer](https://github.com/rails-api/active_model_serializers/pull/1251).
90+
91+
# Drawbacks
92+
93+
This will be a breaking change, so all users serializers will be broken after a
94+
major bump.
95+
All pull requests will need to rebase since the architeture will change a lot.
96+
97+
# Alternatives
98+
99+
We can keep the way it is, and keep in mind to not add another namespace as a
100+
public API.
101+
102+
# Unresolved questions
103+
104+
What is the better class name to be used to the class that will be inherited at
105+
the creation of a serializer. This can be discussed in other RFC or directly via
106+
pull request.

0 commit comments

Comments
 (0)