Skip to content

Commit 4721584

Browse files
committed
Merge branch 'master' into nested-serializers
2 parents 3d86c95 + aaa60bf commit 4721584

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+721
-490
lines changed

.rubocop.yml

Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -8,39 +8,6 @@ AllCops:
88
DisplayCopNames: true
99
DisplayStyleGuide: true
1010

11-
Style/IndentationConsistency:
12-
Exclude:
13-
- lib/active_model/serializer/adapter/flatten_json.rb
14-
- lib/active_model/serializer/adapter/fragment_cache.rb
15-
- lib/active_model/serializer/adapter/json.rb
16-
- lib/active_model/serializer/adapter/json/fragment_cache.rb
17-
- lib/active_model/serializer/adapter/json_api.rb
18-
- lib/active_model/serializer/adapter/json_api/fragment_cache.rb
19-
- lib/active_model/serializer/adapter/json_api/pagination_links.rb
20-
- lib/active_model/serializer/adapter/null.rb
21-
22-
Style/IndentationWidth:
23-
Exclude:
24-
- lib/active_model/serializer/adapter/flatten_json.rb
25-
- lib/active_model/serializer/adapter/fragment_cache.rb
26-
- lib/active_model/serializer/adapter/json.rb
27-
- lib/active_model/serializer/adapter/json/fragment_cache.rb
28-
- lib/active_model/serializer/adapter/json_api.rb
29-
- lib/active_model/serializer/adapter/json_api/fragment_cache.rb
30-
- lib/active_model/serializer/adapter/json_api/pagination_links.rb
31-
- lib/active_model/serializer/adapter/null.rb
32-
33-
Style/AccessModifierIndentation:
34-
Exclude:
35-
- lib/active_model/serializer/adapter/flatten_json.rb
36-
- lib/active_model/serializer/adapter/fragment_cache.rb
37-
- lib/active_model/serializer/adapter/json.rb
38-
- lib/active_model/serializer/adapter/json/fragment_cache.rb
39-
- lib/active_model/serializer/adapter/json_api.rb
40-
- lib/active_model/serializer/adapter/json_api/fragment_cache.rb
41-
- lib/active_model/serializer/adapter/json_api/pagination_links.rb
42-
- lib/active_model/serializer/adapter/null.rb
43-
4411
Lint/NestedMethodDefinition:
4512
Enabled: false
4613
Exclude:

CHANGELOG.md

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
11
### 0.10.0
22

3+
Breaking changes:
4+
* Adapters now inherit Adapter::Base. 'Adapter' is now a module, no longer a class. [@bf4], #1138
5+
* using a class as a namespace that you also inherit from is complicated and circular at time i.e.
6+
buggy (see https://github.com/rails-api/active_model_serializers/pull/1177)
7+
* The class methods on Adapter aren't necessarily related to the instance methods, they're more
8+
Adapter functions
9+
* named `Base` because it's a Rails-ism
10+
* It helps to isolate and highlight what the Adapter interface actually is
11+
12+
Features:
313
* adds adapters pattern
414
* adds support for `meta` and `meta_key` [@kurko]
515
* adds method to override association [@kurko]
@@ -11,4 +21,9 @@
1121
* remove root key option and split JSON adapter [@joaomdmoura]
1222
* adds FlattenJSON as default adapter [@joaomdmoura]
1323
* adds support for `pagination links` at top level of JsonApi adapter [@bacarini]
14-
* adds extended format for `include` option to JSONAPI adapter [@beauby]
24+
* adds extended format for `include` option to JsonApi adapter [@beauby]
25+
* adds support for wildcards in `include` option [@beauby]
26+
27+
Fixes:
28+
29+
Misc:

README.md

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# ActiveModel::Serializer
22

3-
[![Build Status](https://travis-ci.org/rails-api/active_model_serializers.svg)](https://travis-ci.org/rails-api/active_model_serializers)
3+
[![Build Status](https://travis-ci.org/rails-api/active_model_serializers.svg?branch=master)](https://travis-ci.org/rails-api/active_model_serializers)
44
<a href="https://codeclimate.com/github/rails-api/active_model_serializers"><img src="https://codeclimate.com/github/rails-api/active_model_serializers/badges/gpa.svg" /></a>
55
<a href="https://codeclimate.com/github/rails-api/active_model_serializers/coverage"><img src="https://codeclimate.com/github/rails-api/active_model_serializers/badges/coverage.svg" /></a>
66

@@ -12,7 +12,7 @@ AMS does this through two components: **serializers** and **adapters**.
1212
Serializers describe _which_ attributes and relationships should be serialized.
1313
Adapters describe _how_ attributes and relationships should be serialized.
1414

15-
By default AMS will use the **Flatten Json Adapter**. But we strongly advise you to use **JsonApi Adapter** that follows 1.0 of the format specified in [jsonapi.org/format](http://jsonapi.org/format).
15+
By default AMS will use the **Attributes Adapter**. But we strongly advise you to use **JsonApi Adapter** that follows 1.0 of the format specified in [jsonapi.org/format](http://jsonapi.org/format).
1616
Check how to change the adapter in the sections bellow.
1717

1818
# RELEASE CANDIDATE, PLEASE READ
@@ -66,7 +66,7 @@ ActiveModel::Serializer.config.adapter = :json_api
6666
You won't need to implement an adapter unless you wish to use a new format or
6767
media type with AMS.
6868

69-
If you want to have a root key on your responses you should use the Json adapter, instead of the default FlattenJson:
69+
If you want to have a root key on your responses you should use the Json adapter, instead of the default Attributes:
7070

7171
```ruby
7272
ActiveModel::Serializer.config.adapter = :json
@@ -136,7 +136,8 @@ The key can be customized using `meta_key` option.
136136
render json: @post, meta: { total: 10 }, meta_key: "custom_meta"
137137
```
138138

139-
`meta` will only be included in your response if you are using an Adapter that supports `root`, as JsonAPI and Json adapters, the default adapter (FlattenJson) doesn't have `root`.
139+
`meta` will only be included in your response if you are using an Adapter that supports `root`,
140+
as JsonAPI and Json adapters, the default adapter (Attributes) doesn't have `root`.
140141

141142
### Using a serializer without `render`
142143

@@ -189,7 +190,7 @@ end
189190

190191
### Built in Adapters
191192

192-
#### FlattenJSON
193+
#### Attributes
193194

194195
It's the default adapter, it generates a json response without a root key.
195196
Doesn't follow any specifc convention.
@@ -199,7 +200,7 @@ Doesn't follow any specifc convention.
199200
It also generates a json response but always with a root key. The root key **can't be overridden**, and will be automatically defined accordingly with the objects being serialized.
200201
Doesn't follow any specifc convention.
201202

202-
#### JSONAPI
203+
#### JSON API
203204

204205
This adapter follows 1.0 of the format specified in
205206
[jsonapi.org/format](http://jsonapi.org/format). It will include the associated
@@ -285,9 +286,15 @@ And you can change the JSON key that the serializer should use for a particular
285286

286287
## Pagination
287288

288-
Pagination links will be included in your response automatically as long as the resource is paginated using [Kaminari](https://github.com/amatsuda/kaminari) or [WillPaginate](https://github.com/mislav/will_paginate) and if you are using a ```JSON-API``` adapter.
289+
Pagination links will be included in your response automatically as long
290+
as the resource is paginated using [Kaminari](https://github.com/amatsuda/kaminari) or
291+
[WillPaginate](https://github.com/mislav/will_paginate) and
292+
if you are using the ```JsonApi``` adapter.
289293

290-
Although the others adapters does not have this feature, it is possible to implement pagination links to `JSON` adapter. For more information about it, please see in our docs [How to add pagination links](https://github.com/rails-api/active_model_serializers/blob/master/docs/howto/add_pagination_links.md)
294+
Although the others adapters does not have this feature, it is possible to
295+
implement pagination links to `JSON` adapter. For more information about it,
296+
please see in our docs [How to add pagination
297+
links](https://github.com/rails-api/active_model_serializers/blob/master/docs/howto/add_pagination_links.md).
291298

292299
## Caching
293300

active_model_serializers.gemspec

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,9 @@ Gem::Specification.new do |spec|
4242
# 'thread_safe'
4343

4444
# Soft dependency for pagination
45-
spec.add_development_dependency 'kaminari'
46-
spec.add_development_dependency 'will_paginate'
45+
spec.add_development_dependency 'kaminari', ' ~> 0.16.3'
46+
spec.add_development_dependency 'will_paginate', '~> 3.0', '>= 3.0.7'
4747

4848
spec.add_development_dependency 'bundler', '~> 1.6'
49-
spec.add_development_dependency 'timecop', '>= 0.7'
49+
spec.add_development_dependency 'timecop', '~> 0.7'
5050
end

docs/general/adapters.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@
33
AMS does this through two components: **serializers** and **adapters**.
44
Serializers describe _which_ attributes and relationships should be serialized.
55
Adapters describe _how_ attributes and relationships should be serialized.
6-
You can use one of the built-in adapters (```FlattenJSON``` is the default one) or create one by yourself, but you won't need to implement an adapter unless you wish to use a new format or media type with AMS.
6+
You can use one of the built-in adapters (```Attributes``` is the default one) or create one by yourself, but you won't need to implement an adapter unless you wish to use a new format or media type with AMS.
77

88
## Built in Adapters
99

10-
### FlattenJSON - Default
10+
### Attributes - Default
1111

1212
It's the default adapter, it generates a json response without a root key.
1313
Doesn't follow any specifc convention.
@@ -17,7 +17,7 @@ Doesn't follow any specifc convention.
1717
It also generates a json response but always with a root key. The root key **can't be overridden**, and will be automatically defined accordingly to the objects being serialized.
1818
Doesn't follow any specifc convention.
1919

20-
### JSONAPI
20+
### JSON API
2121

2222
This adapter follows **version 1.0** of the format specified in
2323
[jsonapi.org/format](http://jsonapi.org/format). It will include the associated
@@ -51,7 +51,7 @@ ActiveModel::Serializer.config.adapter = :json_api
5151
```
5252

5353
If you want to have a root key for each resource in your responses, you should use the Json or
54-
JsonApi adapters instead of the default FlattenJson:
54+
JsonApi adapters instead of the default Attributes:
5555

5656
```ruby
5757
ActiveModel::Serializer.config.adapter = :json

docs/general/configuration_options.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ The following configuration options can be set on `ActiveModel::Serializer.confi
44

55
## General
66

7-
- `adapter`: The [adapter](adapters.md) to use. Possible values: `:flatten_json, :json, :json_api`. Default: `:flatten_json`.
7+
- `adapter`: The [adapter](adapters.md) to use. Possible values: `:attributes, :json, :json_api`. Default: `:attributes`.
88

99
## JSON API
1010

docs/howto/add_pagination_links.md

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
# How to add pagination links
22

3-
### JSON-API adapter
3+
### JSON API adapter
44

5-
Pagination links will be included in your response automatically as long as the resource is paginated and if you are using a ```JSON-API``` adapter.
5+
Pagination links will be included in your response automatically as long as
6+
the resource is paginated and if you are using the ```JsonApi``` adapter.
67

7-
If you want pagination links in your response, use [Kaminari](https://github.com/amatsuda/kaminari) or [WillPaginate](https://github.com/mislav/will_paginate).
8+
If you want pagination links in your response, use [Kaminari](https://github.com/amatsuda/kaminari)
9+
or [WillPaginate](https://github.com/mislav/will_paginate).
810

911
###### Kaminari examples
12+
1013
```ruby
1114
#array
1215
@posts = Kaminari.paginate_array([1, 2, 3]).page(3).per(1)
@@ -107,6 +110,6 @@ ex.
107110
}
108111
```
109112

110-
### FlattenJSON adapter
113+
### Attributes adapter
111114

112115
This adapter does not allow us to use `meta` key, due to that it is not possible to add pagination links.

docs/howto/add_root_key.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# How to add root key
22

3-
Add the root key to your API is quite simple with AMS. The **Adapter** is what determines the format of your JSON response. The default adapter is the ```FlattenJSON``` which doesn't have the root key, so your response is something similar to:
3+
Add the root key to your API is quite simple with AMS. The **Adapter** is what determines the format of your JSON response. The default adapter is the ```Attributes``` which doesn't have the root key, so your response is something similar to:
44

55
```json
66
{

0 commit comments

Comments
 (0)