jsonapi-serializers 0.2.6 → 0.3.0
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 +9 -0
- data/lib/jsonapi-serializers/serializer.rb +2 -0
- data/lib/jsonapi-serializers/version.rb +1 -1
- data/spec/serializer_spec.rb +8 -0
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e9cf46e555c07d0768d46875258efd3ca3dbb900
|
4
|
+
data.tar.gz: 7f0939ef5407ab803142ebe688e534efecf4514b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: df2806a436090f5e99edfbca11524aa142b378e05b89c4977d916a5c77580baf9f91aeec957565e4320414ce462a9a048e60907a26d6035fc04a85342a143e7b
|
7
|
+
data.tar.gz: 394f4d441286ee6ab265c41be01937664ebee6c7541ebfc47d8f1f888f6fc51e8a223ad5d67ca4287bab6d185c26a556a94221264535eabcd0e892eb9c2d0238
|
data/README.md
CHANGED
@@ -296,6 +296,14 @@ JSONAPI::Serializer.serialize(post, base_url: 'http://example.com')
|
|
296
296
|
|
297
297
|
Note: if you override `self_link` in your serializer and leave out `base_url`, it will not be included.
|
298
298
|
|
299
|
+
### Top-level metadata
|
300
|
+
|
301
|
+
You can pass a `meta` argument to specify top-level metadata:
|
302
|
+
|
303
|
+
```ruby
|
304
|
+
JSONAPI::Serializer.serialize(post, meta: {copyright: 'Copyright 2015 Example Corp.'})
|
305
|
+
```
|
306
|
+
|
299
307
|
## Relationships
|
300
308
|
|
301
309
|
You can easily specify relationships with the `has_one` and `has_many` directives.
|
@@ -510,6 +518,7 @@ end
|
|
510
518
|
|
511
519
|
## Release notes
|
512
520
|
|
521
|
+
* v0.3.0: Add top-level `meta` support.
|
513
522
|
* v0.2.6: Add `base_url` support.
|
514
523
|
* v0.2.5: Allow disabling ambiguous collection checks for Sequel support.
|
515
524
|
* v0.2.4: Improve handling for nil relationship links.
|
@@ -222,6 +222,7 @@ module JSONAPI
|
|
222
222
|
options[:context] = options.delete('context') || options[:context] || {}
|
223
223
|
options[:skip_collection_check] = options.delete('skip_collection_check') || options[:skip_collection_check] || false
|
224
224
|
options[:base_url] = options.delete('base_url') || options[:base_url]
|
225
|
+
options[:meta] = options.delete('meta') || options[:meta]
|
225
226
|
|
226
227
|
# Normalize includes.
|
227
228
|
includes = options[:include]
|
@@ -273,6 +274,7 @@ module JSONAPI
|
|
273
274
|
result = {
|
274
275
|
'data' => primary_data,
|
275
276
|
}
|
277
|
+
result['meta'] = options[:meta] if options[:meta]
|
276
278
|
|
277
279
|
# If 'include' relationships are given, recursively find and include each object.
|
278
280
|
if includes
|
data/spec/serializer_spec.rb
CHANGED
@@ -333,6 +333,14 @@ describe JSONAPI::Serializer do
|
|
333
333
|
'data' => serialize_primary(post, {serializer: MyApp::PostSerializer}),
|
334
334
|
})
|
335
335
|
end
|
336
|
+
it 'can include a top level meta node' do
|
337
|
+
post = create(:post)
|
338
|
+
meta = {authors: ['Yehuda Katz', 'Steve Klabnik'], copyright: 'Copyright 2015 Example Corp.'}
|
339
|
+
expect(JSONAPI::Serializer.serialize(post, meta: meta)).to eq({
|
340
|
+
'meta' => meta,
|
341
|
+
'data' => serialize_primary(post, {serializer: MyApp::PostSerializer}),
|
342
|
+
})
|
343
|
+
end
|
336
344
|
it 'can serialize a single object with an `each` method by passing skip_collection_check: true' do
|
337
345
|
post = create(:post)
|
338
346
|
post.define_singleton_method(:each) do
|
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.
|
4
|
+
version: 0.3.0
|
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-
|
11
|
+
date: 2015-09-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -123,7 +123,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
123
123
|
version: '0'
|
124
124
|
requirements: []
|
125
125
|
rubyforge_project:
|
126
|
-
rubygems_version: 2.
|
126
|
+
rubygems_version: 2.2.2
|
127
127
|
signing_key:
|
128
128
|
specification_version: 4
|
129
129
|
summary: Pure Ruby readonly serializers for the JSON:API spec.
|