active_model_serializers 0.10.10 → 0.10.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +12 -1
- data/README.md +18 -18
- data/lib/active_model/serializer.rb +1 -2
- data/lib/active_model/serializer/concerns/caching.rb +2 -1
- data/lib/active_model/serializer/fieldset.rb +1 -1
- data/lib/active_model/serializer/reflection.rb +4 -4
- data/lib/active_model/serializer/version.rb +1 -1
- data/lib/active_model_serializers/model/caching.rb +25 -0
- metadata +15 -14
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d4efe10f8c12914205c5d3a42c5cac29bdd2d01faea644c67606e0f24fc49ab3
|
4
|
+
data.tar.gz: 9751dfae561915e17ba3d15fa6caf5b0eb2e708c672db64b54aaa5d3f0f8d0b8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8cc6dad9d1b4e3d7fec54bdbf38f70b39d8ed85373a267639996778f02508be82bf19e81b4acecb7d4161939de74da56e45025292cfd06c12a1b35580e283feb
|
7
|
+
data.tar.gz: eeab962f26dea765ea293975744695900654f07e7a001c592f8b748862935f60df12e9f9689166d8babb929fdeb4ca0d060ab0537dcf1b3cbfa8cb5f8b4cbd71
|
data/CHANGELOG.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
## 0.10.x
|
2
2
|
|
3
|
-
### [master (unreleased)](https://github.com/rails-api/active_model_serializers/compare/v0.10.
|
3
|
+
### [master (unreleased)](https://github.com/rails-api/active_model_serializers/compare/v0.10.11...0-10-stable)
|
4
4
|
|
5
5
|
Breaking changes:
|
6
6
|
|
@@ -10,6 +10,17 @@ Fixes:
|
|
10
10
|
|
11
11
|
Misc:
|
12
12
|
|
13
|
+
### [v0.10.11 (2020-12-04)](https://github.com/rails-api/active_model_serializers/compare/v0.10.10...v0.10.11)
|
14
|
+
|
15
|
+
Features:
|
16
|
+
|
17
|
+
- [#2361](https://github.com/rails-api/active_model_serializers/pull/2361) Add `ActiveModelSerializers.config.use_sha1_digests` to allow customization of the hashing algorithm used for serializer caching (@alexzherdev)
|
18
|
+
|
19
|
+
Fixes:
|
20
|
+
|
21
|
+
- [#2344](https://github.com/rails-api/active_model_serializers/pull/2344) Fixes #2341 introduced since #2223 (@wasifhossain)
|
22
|
+
- [#2395](https://github.com/rails-api/active_model_serializers/pull/2395) remove explicit require for thread_safe (@ritikesh)
|
23
|
+
|
13
24
|
### [v0.10.10 (2019-07-13)](https://github.com/rails-api/active_model_serializers/compare/v0.10.9...v0.10.10)
|
14
25
|
|
15
26
|
Fixes:
|
data/README.md
CHANGED
@@ -4,8 +4,8 @@
|
|
4
4
|
<tr>
|
5
5
|
<td>Build Status</td>
|
6
6
|
<td>
|
7
|
-
<a href="https://travis-ci.org/rails-api/active_model_serializers"><img src="https://travis-ci.org/rails-api/active_model_serializers.svg?branch=
|
8
|
-
<a href="https://ci.appveyor.com/project/
|
7
|
+
<a href="https://travis-ci.org/rails-api/active_model_serializers"><img src="https://api.travis-ci.org/rails-api/active_model_serializers.svg?branch=0-10-stable" alt="Build Status" ></a>
|
8
|
+
<a href="https://ci.appveyor.com/project/bf4/active-model-serializers/branch/0-10-stable"><img src="https://ci.appveyor.com/api/projects/status/x6xdjydutm54gvyt/branch/master?svg=true" alt="Build status"></a>
|
9
9
|
</td>
|
10
10
|
</tr>
|
11
11
|
<tr>
|
@@ -41,7 +41,7 @@ these methods to the adapter.)
|
|
41
41
|
|
42
42
|
By default ActiveModelSerializers will use the **Attributes Adapter** (no JSON root).
|
43
43
|
But we strongly advise you to use **JsonApi Adapter**, which
|
44
|
-
follows 1.0 of the format specified in [jsonapi.org/format](
|
44
|
+
follows 1.0 of the format specified in [jsonapi.org/format](https://jsonapi.org/format).
|
45
45
|
Check how to change the adapter in the sections below.
|
46
46
|
|
47
47
|
`0.10.x` is **not** backward compatible with `0.9.x` nor `0.8.x`.
|
@@ -75,9 +75,9 @@ More information is available in the [Guides](docs) and
|
|
75
75
|
If you find a bug, please report an [Issue](https://github.com/rails-api/active_model_serializers/issues/new)
|
76
76
|
and see our [contributing guide](CONTRIBUTING.md).
|
77
77
|
|
78
|
-
If you have a question, please [post to Stack Overflow](
|
78
|
+
If you have a question, please [post to Stack Overflow](https://stackoverflow.com/questions/tagged/active-model-serializers).
|
79
79
|
|
80
|
-
If you'd like to chat, we have a [community slack](
|
80
|
+
If you'd like to chat, we have a [community slack](https://amserializers.herokuapp.com).
|
81
81
|
|
82
82
|
Thanks!
|
83
83
|
|
@@ -87,14 +87,14 @@ If you're reading this at https://github.com/rails-api/active_model_serializers
|
|
87
87
|
reading documentation for our `master`, which may include features that have not
|
88
88
|
been released yet. Please see below for the documentation relevant to you.
|
89
89
|
|
90
|
-
- [0.10 (
|
91
|
-
- [0.10.
|
92
|
-
|
93
|
-
|
90
|
+
- [0.10 (0-10-stable) Documentation](https://github.com/rails-api/active_model_serializers/tree/0-10-stable)
|
91
|
+
- [0.10.10 (latest release) Documentation](https://github.com/rails-api/active_model_serializers/tree/v0.10.10)
|
92
|
+
- [](https://www.rubydoc.info/gems/active_model_serializers/0.10.10)
|
93
|
+
- [Guides](docs)
|
94
94
|
- [0.9 (0-9-stable) Documentation](https://github.com/rails-api/active_model_serializers/tree/0-9-stable)
|
95
|
-
|
95
|
+
- [](https://www.rubydoc.info/gems/active_model_serializers/0.9.7)
|
96
96
|
- [0.8 (0-8-stable) Documentation](https://github.com/rails-api/active_model_serializers/tree/0-8-stable)
|
97
|
-
|
97
|
+
- [](https://www.rubydoc.info/gems/active_model_serializers/0.8.4)
|
98
98
|
|
99
99
|
|
100
100
|
## High-level behavior
|
@@ -171,12 +171,12 @@ The original design is also available [here](https://github.com/rails-api/active
|
|
171
171
|
|
172
172
|
### ActiveModel::Serializer
|
173
173
|
|
174
|
-
An **`ActiveModel::Serializer`** wraps a [serializable resource](https://github.com/rails/rails/blob/
|
174
|
+
An **`ActiveModel::Serializer`** wraps a [serializable resource](https://github.com/rails/rails/blob/master/activemodel/lib/active_model/serialization.rb)
|
175
175
|
and exposes an `attributes` method, among a few others.
|
176
176
|
It allows you to specify which attributes and associations should be represented in the serializatation of the resource.
|
177
177
|
It requires an adapter to transform its attributes into a JSON document; it cannot be serialized itself.
|
178
178
|
It may be useful to think of it as a
|
179
|
-
[presenter](
|
179
|
+
[presenter](https://blog.steveklabnik.com/posts/2011-09-09-better-ruby-presenters).
|
180
180
|
|
181
181
|
#### ActiveModel::CollectionSerializer
|
182
182
|
|
@@ -188,7 +188,7 @@ and, if there is no serializer, primitives.
|
|
188
188
|
The **`ActiveModelSerializers::Adapter::Base`** describes the structure of the JSON document generated from a
|
189
189
|
serializer. For example, the `Attributes` example represents each serializer as its
|
190
190
|
unmodified attributes. The `JsonApi` adapter represents the serializer as a [JSON
|
191
|
-
API](
|
191
|
+
API](https://jsonapi.org/) document.
|
192
192
|
|
193
193
|
### ActiveModelSerializers::SerializableResource
|
194
194
|
|
@@ -229,7 +229,7 @@ High-level overview:
|
|
229
229
|
- `:each_serializer` specifies the serializer for each resource in the collection.
|
230
230
|
- For a **single resource**, the `:serializer` option is the resource serializer.
|
231
231
|
- Options are partitioned in serializer options and adapter options. Keys for adapter options are specified by
|
232
|
-
[`ADAPTER_OPTION_KEYS`](
|
232
|
+
[`ADAPTER_OPTION_KEYS`](lib/active_model_serializers/serializable_resource.rb#L5).
|
233
233
|
The remaining options are serializer options.
|
234
234
|
|
235
235
|
Details:
|
@@ -254,7 +254,7 @@ Details:
|
|
254
254
|
2. `adapter_instance = ActiveModel::Serializer::Adapter.create(serializer_instance, adapter_opts)`
|
255
255
|
1. **ActiveModel::Serializer::CollectionSerializer#new**
|
256
256
|
1. If the `serializer_instance` was a `CollectionSerializer` and the `:serializer` serializer_opts
|
257
|
-
is present, then [that serializer is passed into each resource](https://github.com/rails-api/active_model_serializers/blob/
|
257
|
+
is present, then [that serializer is passed into each resource](https://github.com/rails-api/active_model_serializers/blob/0-10-stable/lib/active_model/serializer/collection_serializer.rb#L77-L79).
|
258
258
|
1. **ActiveModel::Serializer#attributes** is used by the adapter to get the attributes for
|
259
259
|
resource as defined by the serializer.
|
260
260
|
|
@@ -270,7 +270,7 @@ to know about, but not part of ActiveModelSerializers.)
|
|
270
270
|
[(code)](lib/active_model/serializer/lint.rb).
|
271
271
|
|
272
272
|
ActiveModelSerializers provides a
|
273
|
-
[`ActiveModelSerializers::Model`](
|
273
|
+
[`ActiveModelSerializers::Model`](lib/active_model_serializers/model.rb),
|
274
274
|
which is a simple serializable PORO (Plain-Old Ruby Object).
|
275
275
|
|
276
276
|
`ActiveModelSerializers::Model` may be used either as a reference implementation, or in production code.
|
@@ -298,7 +298,7 @@ ActiveModelSerializers::SerializableResource.new(MyModel.new(level: 'awesome'),
|
|
298
298
|
|
299
299
|
## Semantic Versioning
|
300
300
|
|
301
|
-
This project adheres to [semver](
|
301
|
+
This project adheres to [semver](https://semver.org/)
|
302
302
|
|
303
303
|
## Contributing
|
304
304
|
|
@@ -1,6 +1,5 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require 'thread_safe'
|
4
3
|
require 'jsonapi/include_directive'
|
5
4
|
require 'active_model/serializer/collection_serializer'
|
6
5
|
require 'active_model/serializer/array_serializer'
|
@@ -73,7 +72,7 @@ module ActiveModel
|
|
73
72
|
# Used to cache serializer name => serializer class
|
74
73
|
# when looked up by Serializer.get_serializer_for.
|
75
74
|
def self.serializers_cache
|
76
|
-
@serializers_cache ||=
|
75
|
+
@serializers_cache ||= Concurrent::Map.new
|
77
76
|
end
|
78
77
|
|
79
78
|
# @api private
|
@@ -56,7 +56,8 @@ module ActiveModel
|
|
56
56
|
def digest_caller_file(caller_line)
|
57
57
|
serializer_file_path = caller_line[CALLER_FILE]
|
58
58
|
serializer_file_contents = IO.read(serializer_file_path)
|
59
|
-
Digest::MD5
|
59
|
+
algorithm = ActiveModelSerializers.config.use_sha1_digests ? Digest::SHA1 : Digest::MD5
|
60
|
+
algorithm.hexdigest(serializer_file_contents)
|
60
61
|
rescue TypeError, Errno::ENOENT
|
61
62
|
warn <<-EOF.strip_heredoc
|
62
63
|
Cannot digest non-existent file: '#{caller_line}'.
|
@@ -87,8 +87,8 @@ module ActiveModel
|
|
87
87
|
# meta ids: ids
|
88
88
|
# end
|
89
89
|
# end
|
90
|
-
def link(name, value = nil)
|
91
|
-
options[:links][name] = block_given? ?
|
90
|
+
def link(name, value = nil, &block)
|
91
|
+
options[:links][name] = block_given? ? block : value
|
92
92
|
:nil
|
93
93
|
end
|
94
94
|
|
@@ -102,8 +102,8 @@ module ActiveModel
|
|
102
102
|
# href object.blog.id.to_s
|
103
103
|
# meta(id: object.blog.id)
|
104
104
|
# end
|
105
|
-
def meta(value = nil)
|
106
|
-
options[:meta] = block_given? ?
|
105
|
+
def meta(value = nil, &block)
|
106
|
+
options[:meta] = block_given? ? block : value
|
107
107
|
:nil
|
108
108
|
end
|
109
109
|
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module ActiveModelSerializers
|
2
|
+
class Model
|
3
|
+
module Caching
|
4
|
+
extend ActiveSupport::Concern
|
5
|
+
|
6
|
+
included do
|
7
|
+
attr_writer :updated_at
|
8
|
+
attributes :id
|
9
|
+
end
|
10
|
+
|
11
|
+
# Defaults to the downcased model name and updated_at
|
12
|
+
def cache_key
|
13
|
+
ActiveSupport::Cache.expand_cache_key([
|
14
|
+
self.class.model_name.name.downcase,
|
15
|
+
"#{id}-#{updated_at.strftime('%Y%m%d%H%M%S%9N')}"
|
16
|
+
].compact)
|
17
|
+
end
|
18
|
+
|
19
|
+
# Defaults to the time the serializer file was modified.
|
20
|
+
def updated_at
|
21
|
+
defined?(@updated_at) ? @updated_at : File.mtime(__FILE__)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: active_model_serializers
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.10.
|
4
|
+
version: 0.10.11
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Steve Klabnik
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-12-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activemodel
|
@@ -182,28 +182,28 @@ dependencies:
|
|
182
182
|
name: bundler
|
183
183
|
requirement: !ruby/object:Gem::Requirement
|
184
184
|
requirements:
|
185
|
-
- - "
|
185
|
+
- - ">="
|
186
186
|
- !ruby/object:Gem::Version
|
187
|
-
version: '
|
187
|
+
version: '0'
|
188
188
|
type: :development
|
189
189
|
prerelease: false
|
190
190
|
version_requirements: !ruby/object:Gem::Requirement
|
191
191
|
requirements:
|
192
|
-
- - "
|
192
|
+
- - ">="
|
193
193
|
- !ruby/object:Gem::Version
|
194
|
-
version: '
|
194
|
+
version: '0'
|
195
195
|
- !ruby/object:Gem::Dependency
|
196
196
|
name: simplecov
|
197
197
|
requirement: !ruby/object:Gem::Requirement
|
198
198
|
requirements:
|
199
|
-
- - "
|
199
|
+
- - ">="
|
200
200
|
- !ruby/object:Gem::Version
|
201
201
|
version: '0.11'
|
202
202
|
type: :development
|
203
203
|
prerelease: false
|
204
204
|
version_requirements: !ruby/object:Gem::Requirement
|
205
205
|
requirements:
|
206
|
-
- - "
|
206
|
+
- - ">="
|
207
207
|
- !ruby/object:Gem::Version
|
208
208
|
version: '0.11'
|
209
209
|
- !ruby/object:Gem::Dependency
|
@@ -263,7 +263,7 @@ dependencies:
|
|
263
263
|
version: '10.0'
|
264
264
|
- - "<"
|
265
265
|
- !ruby/object:Gem::Version
|
266
|
-
version: '
|
266
|
+
version: '13.0'
|
267
267
|
type: :development
|
268
268
|
prerelease: false
|
269
269
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -273,7 +273,7 @@ dependencies:
|
|
273
273
|
version: '10.0'
|
274
274
|
- - "<"
|
275
275
|
- !ruby/object:Gem::Version
|
276
|
-
version: '
|
276
|
+
version: '13.0'
|
277
277
|
description: ActiveModel::Serializers allows you to generate your JSON in an object-oriented
|
278
278
|
and convention-driven manner.
|
279
279
|
email:
|
@@ -334,6 +334,7 @@ files:
|
|
334
334
|
- lib/active_model_serializers/logging.rb
|
335
335
|
- lib/active_model_serializers/lookup_chain.rb
|
336
336
|
- lib/active_model_serializers/model.rb
|
337
|
+
- lib/active_model_serializers/model/caching.rb
|
337
338
|
- lib/active_model_serializers/railtie.rb
|
338
339
|
- lib/active_model_serializers/register_jsonapi_renderer.rb
|
339
340
|
- lib/active_model_serializers/serializable_resource.rb
|
@@ -353,7 +354,7 @@ homepage: https://github.com/rails-api/active_model_serializers
|
|
353
354
|
licenses:
|
354
355
|
- MIT
|
355
356
|
metadata: {}
|
356
|
-
post_install_message:
|
357
|
+
post_install_message:
|
357
358
|
rdoc_options: []
|
358
359
|
require_paths:
|
359
360
|
- lib
|
@@ -368,8 +369,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
368
369
|
- !ruby/object:Gem::Version
|
369
370
|
version: '0'
|
370
371
|
requirements: []
|
371
|
-
rubygems_version: 3.
|
372
|
-
signing_key:
|
372
|
+
rubygems_version: 3.1.4
|
373
|
+
signing_key:
|
373
374
|
specification_version: 4
|
374
375
|
summary: Conventions-based JSON generation for Rails.
|
375
376
|
test_files: []
|