Skip to content

Commit 2f8c430

Browse files
committed
Update the RFC to use ActiveModelSerializers
After some internal discussion was decided to use the ActiveModelSerializers namespace. This patch update the content following this idea. Ref: https://github.com/rails-api/active_model_serializers/pull/1310/files#r45947587 https://github.com/rails-api/active_model_serializers/pull/1310/files#r47144210
1 parent a183645 commit 2f8c430

File tree

1 file changed

+49
-58
lines changed

1 file changed

+49
-58
lines changed

docs/rfcs/0000-namespace.md

Lines changed: 49 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
- Start Date: (2015-10-29)
2-
- RFC PR: (leave this empty)
3-
- AMS Issue: (leave this empty)
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
44

55
# Summary
66

@@ -25,91 +25,82 @@ At `ActiveModel` we have:
2525

2626
- `ActiveModel::SerializableResource`
2727

28-
The idea here is to provide a single namespace `ActiveModel::Serializers` to the user.
28+
The idea here is to provide a single namespace `ActiveModelSerializers` to the user.
2929
Following the same idea we have on other gems like
3030
[Devise](https://github.com/plataformatec/devise/blob/e9c82472ffe7c43a448945f77e034a0e47dde0bb/lib/devise.rb),
3131
[Refile](https://github.com/refile/refile/blob/6b24c293d044862dafbf1bfa4606672a64903aa2/lib/refile.rb) and
3232
[Active Job](https://github.com/rails/rails/blob/30bacc26f8f258b39e12f63fe52389a968d9c1ea/activejob/lib/active_job.rb)
3333
for example.
3434

35-
# Detailed design
36-
37-
## Require statement and main module
38-
39-
We are adding a extension for the Active Model, so
40-
[following the Rubygens recomendation](http://guides.rubygems.org/name-your-gem/)
41-
for the gem name we need to change to this.
42-
43-
|Gem name | Require statement | Main class or module |
44-
|--------------------------|----------------------------|--------------------------|
45-
| active_model_serializers | `active_model/serializers` | ActiveModel::Serializers |
46-
47-
The expected gem name, in the gemspec is `active_model-serializers` but we don't
48-
need to change this, we can change the code without the need of a new gem on Rubygems.
49-
50-
Active Model for example follow the same idea the gem name on gemspec is `activemodel` and to the end user is:
51-
52-
|Gem name | Require statement | Main class or module |
53-
|--------------------------|----------------------------|--------------------------|
54-
| activemodel | `active_model` | ActiveModel |
55-
56-
As you can see we do not require `activemodel`(the gem name in gemspec) insted
57-
we use `active_model`.
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.
5839

59-
And based on the [bump of `0.10.0.pre` released by Steve Klabnik](https://github.com/rails-api/active_model_serializers/tree/86fc7d7227f3ce538fcb28c1e8c7069ce311f0e1)
60-
if we take a look on README and gemspec always is used `ActiveModel::Serializers`.
40+
# Detailed design
6141

6242
## New classes and modules organization
6343

64-
Since this will be a big change we can do this on baby steps, read small PRs. A
44+
Since this will be a big change we can do this on baby steps, read small pull requests. A
6545
possible approach is:
6646

67-
- Create the `ActiveModel::Serializers` namespace;
68-
- Move all content under `ActiveModelSerializers` to be under
69-
`ActiveModel::Serializers`, the logger is on this step;
47+
- All new code will be in `lib/active_model_serializers/` using
48+
the module namespace `ActiveModelSerializers`.
7049
- Move all content under `ActiveModel::Serializer` to be under
71-
`ActiveModel::Serializers`, the adapter is on this steps;
72-
- Move all content under `ActiveModel` to be under `ActiveModel::Serializers`,
50+
`ActiveModelSerializers`, the adapter is on this steps;
51+
- Move all content under `ActiveModel` to be under `ActiveModelSerializers`,
7352
the `SerializableResource` is on this step;
74-
- Now that all the code lives under `ActiveModel::Serializers` we can:
75-
- create a better name to the `ActiveModel::Serializers::Serializer`
76-
keeping in mind only to keep this in the same namespace
77-
- create a better name to the `ActiveModel::Serializers::Serializer::Adapter::JsonApi`
78-
probably remove this from the `ActiveModel::Serializers::Serializer`
79-
and do something like `ActiveModel::Serializers::Adapter::JsonApi`
80-
keeping in mind only to keep this in the same namespace
81-
- Change all public API that doesn't make sense, keeping in mind only to keep
82-
this in the same namespace
53+
- Change all public API that doesn't make sense, keeping in mind only to keep
54+
this in the same namespace
8355
- Update the README;
8456
- Update the docs;
8557

8658
The following table represents the current and the desired classes and modules
8759
at the first moment.
8860

89-
| Current | Desired | Notes |
90-
|-------------------------------------------------------|--------------------------------------------------|--------------------|
91-
|`ActiveModelSerializers` and `ActiveModel::Serializer` | `ActiveModel::Serializers` | The main namespace |
92-
| `ActiveModelSerializers.logger` | `ActiveModel::Serializers.logger` ||
93-
|`ActiveModelSerializers::Model` | `ActiveModel::Serializers::Model` ||
94-
|`ActiveModel::SerializableResource` | `ActiveModel::Serializers::SerializableResource` ||
95-
| `ActiveModel::Serializer` | `ActiveModel::Serializers::Serializer` | I know that is probably a bad name, but In a second moment we can rename this to `Resource` [for example following this idea](https://github.com/rails-api/active_model_serializers/pull/1301/files#r42963185)|
96-
|`ActiveModel::Serializer.config` | `ActiveModel::Serializers.config` ||
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).
9790

9891
# Drawbacks
9992

100-
This will be a breaking change, so all users serializers will be broken.
101-
All PRs will need to rebase since the architeture will change a lot.
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.
10296

10397
# Alternatives
10498

10599
We can keep the way it is, and keep in mind to not add another namespace as a
106100
public API.
107101

108-
Or we can start moving the small ones that seems to be the
109-
`ActiveModelSerializers` and `ActiveModel` and later we can handle the
110-
`ActiveModel::Serializer`.
111-
112102
# Unresolved questions
113103

114104
What is the better class name to be used to the class that will be inherited at
115-
the creation of a serializer.
105+
the creation of a serializer. This can be discussed in other RFC or directly via
106+
pull request.

0 commit comments

Comments
 (0)