Skip to content

Commit 25c9df0

Browse files
committed
Merge branch 'master' into domitian-move-namespace-of-adapter-to-active-model-serializers
Conflicts: CHANGELOG.md lib/active_model/serializer/adapter/attributes.rb lib/active_model/serializer/adapter/cached_serializer.rb lib/active_model/serializer/adapter/fragment_cache.rb lib/active_model/serializer/adapter/json_api.rb lib/active_model/serializer/adapter/json_api/link.rb test/adapter/fragment_cache_test.rb test/adapter/json_api/links_test.rb test/adapter/json_api/resource_type_config_test.rb
2 parents 252f9c4 + 532828b commit 25c9df0

39 files changed

+1343
-327
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,4 @@ tmp
2222
.ruby-version
2323
.ruby-gemset
2424
vendor/bundle
25+
tags

.simplecov

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ ENV['FULL_BUILD'] ||= ENV['CI']
1919
# rubocop:enable Style/DoubleNegation
2020

2121
## CONFIGURE SIMPLECOV
22-
SimpleCov.pid = $$ # In case there's any forking
2322

2423
SimpleCov.profiles.define 'app' do
2524
coverage_dir 'coverage'

CHANGELOG.md

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,30 @@
11
## 0.10.x
22

33
Breaking changes:
4+
45
Features:
6+
- [#1515](https://github.com/rails-api/active_model_serializers/pull/1515) Adds support for symbols to the
7+
`ActiveModel::Serializer.type` method. (@groyoh)
8+
- [#1504](https://github.com/rails-api/active_model_serializers/pull/1504) Adds the changes missing from #1454
9+
and add more tests for resource identifier and relationship objects. Fix association block with link
10+
returning `data: nil`.(@groyoh)
11+
- [#1372](https://github.com/rails-api/active_model_serializers/pull/1372) Support
12+
cache_store.read_multi. (@LcpMarvel)
13+
- [#1018](https://github.com/rails-api/active_model_serializers/pull/1018) Add more tests and docs for top-level links. (@leandrocp)
14+
- [#1454](https://github.com/rails-api/active_model_serializers/pull/1454) Add support for
15+
relationship-level links and meta attributes. (@beauby)
16+
- [#1340](https://github.com/rails-api/active_model_serializers/pull/1340) Add support for resource-level meta. (@beauby)
17+
518
Fixes:
19+
- [#1516](https://github.com/rails-api/active_model_serializers/pull/1501) No longer return a nil href when only
20+
adding meta to a relationship link. (@groyoh)
21+
- [#1458](https://github.com/rails-api/active_model_serializers/pull/1458) Preserve the serializer
22+
type when fragment caching. (@bdmac)
23+
- [#1477](https://github.com/rails-api/active_model_serializers/pull/1477) Fix `fragment_cached?`
24+
method to check if caching. (@bdmac)
25+
- [#1501](https://github.com/rails-api/active_model_serializers/pull/1501) Adds tests for SerializableResource::use_adapter?,doc typos (@domitian)
626
- [#1488](https://github.com/rails-api/active_model_serializers/pull/1488) Require ActiveSupport's string inflections (@nate00)
27+
728
Misc:
829

930
### v0.10.0.rc4 (2016/01/27 11:00 +00:00)
@@ -415,7 +436,7 @@ Features:
415436
'[Revert the serializers API as other alternatives are now also under discussion](https://github.com/rails/rails/commit/0a4035b12a6c59253cb60f9e3456513c6a6a9d33)'.
416437
- [Proposed Implementation to Rails 3.2 by @wycats and @josevalim (November 25, 2011)](https://github.com/rails/rails/pull/3753)
417438
- [Creation of `ActionController::Serialization`, initial serializer
418-
support (September, 26 2011)](https://github.com/rails/rails/commit/8ff7693a8dc61f43fc4eaf72ed24d3b8699191fe0).
439+
support (September, 26 2011)](https://github.com/rails/rails/commit/8ff7693a8dc61f43fc4eaf72ed24d3b8699191fe).
419440
- [Docs and CHANGELOG](https://github.com/rails/rails/commit/696d01f7f4a8ed787924a41cce6df836cd73c46f)
420441
- [Deprecation of ActiveModel::Serialization to ActiveModel::Serializable](https://github.com/rails/rails/blob/696d01f7f4a8ed787924a41cce6df836cd73c46f/activemodel/lib/active_model/serialization.rb)
421442
- [Creation of `ActiveModel::Serialization` from `ActiveModel::Serializer` in Rails (2009)](https://github.com/rails/rails/commit/c6bc8e662614be711f45a8d4b231d5f993b024a7#diff-d029b9768d8df0407a35804a468e3ae5)

Gemfile

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ group :test do
4141
gem 'activerecord-jdbcsqlite3-adapter', platform: :jruby
4242

4343
gem 'codeclimate-test-reporter', require: false
44-
gem 'simplecov', '~> 0.10', require: false, group: :development
4544
end
4645

4746
group :development, :test do

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
(Windows: [![Build status](https://ci.appveyor.com/api/projects/status/x6xdjydutm54gvyt/branch/master?svg=true)](https://ci.appveyor.com/project/joaomdmoura/active-model-serializers/branch/master))
55
[![Code Quality](https://codeclimate.com/github/rails-api/active_model_serializers/badges/gpa.svg)](https://codeclimate.com/github/rails-api/active_model_serializers)
66
[![Test Coverage](https://codeclimate.com/github/rails-api/active_model_serializers/badges/coverage.svg)](https://codeclimate.com/github/rails-api/active_model_serializers/coverage)
7+
[![Issue Stats](http://issuestats.com/github/rails-api/active_model_serializers/badge/pr)](http://issuestats.com/github/rails-api/active_model_serializers) [![Issue Stats](http://issuestats.com/github/rails-api/active_model_serializers/badge/issue)](http://issuestats.com/github/rails-api/active_model_serializers)
78

89
## Documentation
910

Rakefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ else
2929
Rake::Task[:rubocop].clear if Rake::Task.task_defined?(:rubocop)
3030
desc 'Execute rubocop'
3131
RuboCop::RakeTask.new(:rubocop) do |task|
32-
task.options = ['--rails', '--display-cop-names', '--display-style-guide']
32+
task.options = ['--display-cop-names', '--display-style-guide']
3333
task.fail_on_error = true
3434
end
3535
end

active_model_serializers.gemspec

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ Gem::Specification.new do |spec|
5151
spec.add_development_dependency 'will_paginate', '~> 3.0', '>= 3.0.7'
5252

5353
spec.add_development_dependency 'bundler', '~> 1.6'
54+
spec.add_development_dependency 'simplecov', '~> 0.11'
5455
spec.add_development_dependency 'timecop', '~> 0.7'
5556
spec.add_development_dependency 'minitest-reporters'
5657
spec.add_development_dependency 'grape', ['>= 0.13', '< 1.0']

docs/ARCHITECTURE.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,15 +56,15 @@ High-level overview:
5656
- `:each_serializer` specifies the serializer for each resource in the collection.
5757
- For a single resource, the `:serializer` option is the resource serializer.
5858
- Options are partitioned in serializer options and adapter options. Keys for adapter options are specified by
59-
[`ADAPTER_OPTIONS`](https://github.com/rails-api/active_model_serializers/blob/master/lib/active_model/serializable_resource.rb#L4).
59+
[`ADAPTER_OPTION_KEYS`](https://github.com/rails-api/active_model_serializers/blob/master/lib/active_model/serializable_resource.rb#L4).
6060
The remaining options are serializer options.
6161

6262
Details:
6363

6464
1. **ActionController::Serialization**
6565
1. `serializable_resource = ActiveModel::SerializableResource.new(resource, options)`
6666
1. `options` are partitioned into `adapter_opts` and everything else (`serializer_opts`).
67-
The adapter options keys for the are defined by `ADAPTER_OPTIONS`.
67+
The `adapter_opts` keys are defined in `ActiveModel::SerializableResource::ADAPTER_OPTION_KEYS`.
6868
1. **ActiveModel::SerializableResource**
6969
1. `if serializable_resource.serializer?` (there is a serializer for the resource, and an adapter is used.)
7070
- Where `serializer?` is `use_adapter? && !!(serializer)`

docs/general/rendering.md

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,46 @@ PR please :)
103103

104104
#### links
105105

106-
PR please :)
106+
##### How to add top-level links
107+
108+
JsonApi supports a [links object](http://jsonapi.org/format/#document-links) to be specified at top-level, that you can specify in the `render`:
109+
110+
```ruby
111+
links_object = {
112+
href: "http://example.com/api/posts",
113+
meta: {
114+
count: 10
115+
}
116+
}
117+
render json: @posts, links: links_object
118+
```
119+
120+
That's the result:
121+
122+
```json
123+
{
124+
"data": [
125+
{
126+
"type": "posts",
127+
"id": "1",
128+
"attributes": {
129+
"title": "JSON API is awesome!",
130+
"body": "You should be using JSON API",
131+
"created": "2015-05-22T14:56:29.000Z",
132+
"updated": "2015-05-22T14:56:28.000Z"
133+
}
134+
}
135+
],
136+
"links": {
137+
"href": "http://example.com/api/posts",
138+
"meta": {
139+
"count": 10
140+
}
141+
}
142+
}
143+
```
144+
145+
This feature is specific to JsonApi, so you have to use the use the [JsonApi Adapter](adapters.md#jsonapi)
107146

108147
### serializer_opts
109148

docs/general/serializers.md

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,12 +107,30 @@ end
107107

108108
#### ::type
109109

110-
e.g.
110+
The `::type` method defines the JSONAPI [type](http://jsonapi.org/format/#document-resource-object-identification) that will be rendered for this serializer.
111+
It either takes a `String` or `Symbol` as parameter.
112+
113+
Note: This method is useful only when using the `:json_api` adapter.
111114

115+
Examples:
112116
```ruby
113117
class UserProfileSerializer < ActiveModel::Serializer
114118
type 'profile'
115119
end
120+
class AuthorProfileSerializer < ActiveModel::Serializer
121+
type :profile
122+
end
123+
```
124+
125+
With the `:json_api` adapter, the previous serializers would be rendered as:
126+
127+
``` json
128+
{
129+
"data": {
130+
"id": "1",
131+
"type": "profile"
132+
}
133+
}
116134
```
117135

118136
#### ::link

0 commit comments

Comments
 (0)