jsonapi-serializers 0.3.1 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: adb7f4634374e6733cd5a2e1dee11e7863b64922
4
- data.tar.gz: 3d3d1a0225b0a96d681918dcc4fefde4e3df9668
3
+ metadata.gz: 492ef52b3e744f06e226ebe911fd6671dfc637b6
4
+ data.tar.gz: 19f25d49bb9bb8450b9538bdc31aaf6ee4bf3a12
5
5
  SHA512:
6
- metadata.gz: fe35e4ad8cfa091a813fb5e30542482c5b4c9214b068cd5f490d4b71c4e155794c12d05be0ab17b95fc4c8ec7bd2f088c240c25727fc938c75df583596709791
7
- data.tar.gz: 176d36a30d6165a1a7463d0cf87e36349fabb64bfdbeb09b7e67d5f86a1d3052610b8b870883426622a00e9018aabd47765bfc8546e6270a67e2be2e67f9567d
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.
@@ -17,6 +17,10 @@ module JSONAPI
17
17
  add_attribute(name, options, &block)
18
18
  end
19
19
 
20
+ def attributes(*names)
21
+ names.each { |name| add_attribute(name) }
22
+ end
23
+
20
24
  def has_one(name, options = {}, &block)
21
25
  add_to_one_association(name, options, &block)
22
26
  end
@@ -1,5 +1,5 @@
1
1
  module JSONAPI
2
2
  module Serializer
3
- VERSION = '0.3.1'
3
+ VERSION = '0.4.0'
4
4
  end
5
5
  end
@@ -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
@@ -134,4 +134,10 @@ module MyApp
134
134
  class EmptySerializer
135
135
  include JSONAPI::Serializer
136
136
  end
137
+
138
+ class MultipleAttributesSerializer
139
+ include JSONAPI::Serializer
140
+
141
+ attributes :title, :body
142
+ end
137
143
  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.3.1
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: 2015-12-07 00:00:00.000000000 Z
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.2.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: