jsonapi-serializers 0.3.1 → 0.4.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/attributes.rb +4 -0
- data/lib/jsonapi-serializers/version.rb +1 -1
- data/spec/serializer_spec.rb +15 -0
- data/spec/support/serializers.rb +6 -0
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 492ef52b3e744f06e226ebe911fd6671dfc637b6
|
4
|
+
data.tar.gz: 19f25d49bb9bb8450b9538bdc31aaf6ee4bf3a12
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1ad6cd857ffccc11bccf9ee0d33aa0c35dddb8f6da4b188984ac56609c3e38d9373c66fb12518045dec75ebf26473a7624002dc8d1ecb16ea9eb784f0ace8dac
|
7
|
+
data.tar.gz: b6212c674cd0d71bf345aeca14c6e8215e13b9b06614a03510cee65311ef09164b8b7f7effa460a729083963c8d60ae141acf1a62650e4016aa705dd49e5c937
|
data/README.md
CHANGED
@@ -14,6 +14,7 @@ This library is up-to-date with the finalized v1 JSON API spec.
|
|
14
14
|
* [Serialize an object](#serialize-an-object)
|
15
15
|
* [Serialize a collection](#serialize-a-collection)
|
16
16
|
* [Null handling](#null-handling)
|
17
|
+
* [Multiple attributes](#multiple-attributes)
|
17
18
|
* [Custom attributes](#custom-attributes)
|
18
19
|
* [More customizations](#more-customizations)
|
19
20
|
* [Base URL](#base-url)
|
@@ -149,6 +150,13 @@ Returns:
|
|
149
150
|
|
150
151
|
Note that the JSON:API spec distinguishes in how null/empty is handled for single objects vs. collections, so you must always provide `is_collection: true` when serializing multiple objects. If you attempt to serialize multiple objects without this flag (or a single object with it on) a `JSONAPI::Serializer::AmbiguousCollectionError` will be raised.
|
151
152
|
|
153
|
+
### Multiple attributes
|
154
|
+
You could declare multiple attributes at once:
|
155
|
+
|
156
|
+
```ruby
|
157
|
+
attributes :title, :body, :contents
|
158
|
+
```
|
159
|
+
|
152
160
|
### Custom attributes
|
153
161
|
|
154
162
|
By default the serializer looks for the same name of the attribute on the object it is given. You can customize this behavior by providing a block to `attribute`, `has_one`, or `has_many`:
|
@@ -519,6 +527,7 @@ end
|
|
519
527
|
|
520
528
|
## Release notes
|
521
529
|
|
530
|
+
* v0.4.0: Support for declaring multiple `attributes`.
|
522
531
|
* v0.3.1: Improve performance of loading included relationships.
|
523
532
|
* v0.3.0: Add top-level `meta` support.
|
524
533
|
* v0.2.6: Add `base_url` support.
|
data/spec/serializer_spec.rb
CHANGED
@@ -128,6 +128,21 @@ describe JSONAPI::Serializer do
|
|
128
128
|
},
|
129
129
|
})
|
130
130
|
end
|
131
|
+
it 'serializes object when multiple attributes are declared once' do
|
132
|
+
post = create(:post)
|
133
|
+
primary_data = serialize_primary(post, {serializer: MyApp::MultipleAttributesSerializer})
|
134
|
+
expect(primary_data).to eq({
|
135
|
+
'id' => '1',
|
136
|
+
'type' => 'posts',
|
137
|
+
'attributes' => {
|
138
|
+
'title' => 'Title for Post 1',
|
139
|
+
'body' => 'Body for Post 1',
|
140
|
+
},
|
141
|
+
'links' => {
|
142
|
+
'self' => '/posts/1',
|
143
|
+
}
|
144
|
+
})
|
145
|
+
end
|
131
146
|
end
|
132
147
|
context 'with linkage includes' do
|
133
148
|
it 'can serialize primary data for a null to-one relationship' do
|
data/spec/support/serializers.rb
CHANGED
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.4.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:
|
11
|
+
date: 2016-01-15 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.4.5
|
127
127
|
signing_key:
|
128
128
|
specification_version: 4
|
129
129
|
summary: Pure Ruby readonly serializers for the JSON:API spec.
|
@@ -132,3 +132,4 @@ test_files:
|
|
132
132
|
- spec/spec_helper.rb
|
133
133
|
- spec/support/factory.rb
|
134
134
|
- spec/support/serializers.rb
|
135
|
+
has_rdoc:
|