jsonapi-serializers 0.2.4 → 0.2.5
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/README.md +2 -0
- data/lib/jsonapi-serializers/serializer.rb +4 -3
- data/lib/jsonapi-serializers/version.rb +1 -1
- data/spec/serializer_spec.rb +10 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 83d249f8286496af92b2caa669aede02fae2def8
|
4
|
+
data.tar.gz: 660a8816d3b5fa6bb4c1d173cc7aceabca5c0550
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1843eb6c3c067686497e28efc782328d1bbaf4571d25bc7fd87bf7bb46188119894db28f4d7072adaa5de3c823881a5b09699b3dcd5e7b5e6dd835f0882b7a9f
|
7
|
+
data.tar.gz: 3de93fc69bd9a1350d7246054858c4b623c3b9a7cb84057ba2d322042b6b32937e275f01f8eeb79a5fc98e7a4b6ed72a5d18e6b870f80d90563af83d061ed537
|
data/README.md
CHANGED
@@ -439,6 +439,8 @@ end
|
|
439
439
|
|
440
440
|
## Release notes
|
441
441
|
|
442
|
+
* v0.2.5: Allow disabling ambiguous collection checks for Sequel support.
|
443
|
+
* v0.2.4: Improve handling for nil relationship links.
|
442
444
|
* v0.2.3: Support serializers with no attributes.
|
443
445
|
* v0.2.2: Compliance fix for excluding empty relationship objects.
|
444
446
|
* v0.2.1: Compliance fix for self links.
|
@@ -213,6 +213,7 @@ module JSONAPI
|
|
213
213
|
options[:include] = options.delete('include') || options[:include]
|
214
214
|
options[:serializer] = options.delete('serializer') || options[:serializer]
|
215
215
|
options[:context] = options.delete('context') || options[:context] || {}
|
216
|
+
options[:skip_collection_check] = options.delete('skip_collection_check') || options[:skip_collection_check] || false
|
216
217
|
|
217
218
|
# Normalize includes.
|
218
219
|
includes = options[:include]
|
@@ -225,7 +226,7 @@ module JSONAPI
|
|
225
226
|
include: includes
|
226
227
|
}
|
227
228
|
|
228
|
-
if options[:is_collection] && !objects.respond_to?(:each)
|
229
|
+
if !options[:skip_collection_check] && options[:is_collection] && !objects.respond_to?(:each)
|
229
230
|
raise JSONAPI::Serializer::AmbiguousCollectionError.new(
|
230
231
|
'Attempted to serialize a single object as a collection.')
|
231
232
|
end
|
@@ -252,7 +253,7 @@ module JSONAPI
|
|
252
253
|
# Duck-typing check for a collection being passed without is_collection true.
|
253
254
|
# We always must be told if serializing a collection because the JSON:API spec distinguishes
|
254
255
|
# how to serialize null single resources vs. empty collections.
|
255
|
-
if objects.respond_to?(:each)
|
256
|
+
if !options[:skip_collection_check] && objects.respond_to?(:each)
|
256
257
|
raise JSONAPI::Serializer::AmbiguousCollectionError.new(
|
257
258
|
'Must provide `is_collection: true` to `serialize` when serializing collections.')
|
258
259
|
end
|
@@ -444,4 +445,4 @@ module JSONAPI
|
|
444
445
|
end
|
445
446
|
class << self; protected :merge_relationship_path; end
|
446
447
|
end
|
447
|
-
end
|
448
|
+
end
|
data/spec/serializer_spec.rb
CHANGED
@@ -333,6 +333,15 @@ describe JSONAPI::Serializer do
|
|
333
333
|
'data' => serialize_primary(post, {serializer: MyApp::PostSerializer}),
|
334
334
|
})
|
335
335
|
end
|
336
|
+
it 'can serialize a single object with an `each` method by passing skip_collection_check: true' do
|
337
|
+
post = create(:post)
|
338
|
+
post.define_singleton_method(:each) do
|
339
|
+
"defining this just to defeat the duck-type check"
|
340
|
+
end
|
341
|
+
expect(JSONAPI::Serializer.serialize(post, skip_collection_check: true)).to eq({
|
342
|
+
'data' => serialize_primary(post, {serializer: MyApp::PostSerializer}),
|
343
|
+
})
|
344
|
+
end
|
336
345
|
it 'can serialize a collection' do
|
337
346
|
posts = create_list(:post, 2)
|
338
347
|
expect(JSONAPI::Serializer.serialize(posts, is_collection: true)).to eq({
|
@@ -696,4 +705,4 @@ describe JSONAPI::Serializer do
|
|
696
705
|
xit 'is correctly passed through all serializers' do
|
697
706
|
end
|
698
707
|
end
|
699
|
-
end
|
708
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jsonapi-serializers
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mike Fotinakis
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-07-
|
11
|
+
date: 2015-07-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|