jsonapi-serializers 0.8.0 → 0.9.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: cd3e1e9535b28c3bd4aa6649bce141d36c312edc
4
- data.tar.gz: 44a9e5b6079c4b8fc61a871f28e63914df7b6d94
3
+ metadata.gz: ea36d39568cd4df788499db7681358013569975f
4
+ data.tar.gz: 9487670f424a8d0191a157b6dc556a8964fc47c3
5
5
  SHA512:
6
- metadata.gz: a70aa04850d27c037bed576a368f74d76b4e8eda1ef40b65b933e04b1abcf2151245026461114dd19fe61b3f0e13265a9ba513e7606acbe4d10927d20bc48d87
7
- data.tar.gz: d41530712d4454f0e73dead332a0e657853fe74d5f3a1f1ee2c400b7fb7c150d57e074af0c628b30106ced93ef2ed41d5c44a98d90fe195964ec37be2a369ecf
6
+ metadata.gz: de078d2a6e9eba0f0c3a18e90e2f2826997e7bbd7a9eb77ff24dd9eadc57d19011fe771db95a31c762efc80f178cefd1ba79e90dd088af762d9dc0553b58cde3
7
+ data.tar.gz: f0bbd2106ce7a6aec5e6d0d4b722d3e08e75266bb3688a8b92f615748c5586a048dae1f8ca9e2c36a4d412e0aaf5f5735d91d1eb1b9346e5619d4ab03cbcc384
data/README.md CHANGED
@@ -318,11 +318,11 @@ JSONAPI::Serializer.serialize(post, meta: {copyright: 'Copyright 2015 Example Co
318
318
 
319
319
  ### Root errors
320
320
 
321
- You can pass an `errors` argument to specify top-level errors:
321
+ You can use `serialize_errors` method in order to specify top-level errors:
322
322
 
323
323
  ```ruby
324
324
  errors = [{ "title": "Invalid Attribute", "detail": "First name must contain at least three characters." }]
325
- JSONAPI::Serializer.serialize(post, errors: errors)
325
+ JSONAPI::Serializer.serialize_errors(errors)
326
326
  ```
327
327
 
328
328
  ### Explicit serializer discovery
@@ -662,6 +662,8 @@ end
662
662
 
663
663
  ## Release notes
664
664
 
665
+ * v0.9.0: Add initial `serialize_errors` support.
666
+ * v0.8.0: Pass context through recursive relationships.
665
667
  * v0.7.0: Support for root error objects.
666
668
  * v0.6.5: Exclude attributes when empty.
667
669
  * v0.6.4: Fix regression of including links when empty.
@@ -235,6 +235,8 @@ module JSONAPI
235
235
  options[:skip_collection_check] = options.delete('skip_collection_check') || options[:skip_collection_check] || false
236
236
  options[:base_url] = options.delete('base_url') || options[:base_url]
237
237
  options[:meta] = options.delete('meta') || options[:meta]
238
+
239
+ # Deprecated: use serialize_errors method instead
238
240
  options[:errors] = options.delete('errors') || options[:errors]
239
241
 
240
242
  # Normalize includes.
@@ -314,6 +316,10 @@ module JSONAPI
314
316
  result
315
317
  end
316
318
 
319
+ def self.serialize_errors(errors)
320
+ {'errors' => errors}
321
+ end
322
+
317
323
  def self.serialize_primary(object, options = {})
318
324
  serializer_class = options[:serializer] || find_serializer_class(object)
319
325
 
@@ -400,11 +406,8 @@ module JSONAPI
400
406
  # We're finding relationships for compound documents, so skip anything that doesn't exist.
401
407
  next if object.nil?
402
408
 
403
- # We only include parent values if the sential value _include is set. This satifies the
404
- # spec note: A request for comments.author should not automatically also include comments
405
- # in the response. This can happen if the client already has the comments locally, and now
406
- # wants to fetch the associated authors without fetching the comments again.
407
- # http://jsonapi.org/format/#fetching-includes
409
+ # Full linkage: a request for comments.author MUST automatically include comments
410
+ # in the response.
408
411
  objects = is_collection ? object : [object]
409
412
  if child_inclusion_tree[:_include] == true
410
413
  # Include the current level objects if the _include attribute exists.
@@ -1,5 +1,5 @@
1
1
  module JSONAPI
2
2
  module Serializer
3
- VERSION = '0.8.0'
3
+ VERSION = '0.9.0'
4
4
  end
5
5
  end
@@ -381,7 +381,7 @@ describe JSONAPI::Serializer do
381
381
  'data' => serialize_primary(post, {serializer: MyApp::PostSerializer}),
382
382
  })
383
383
  end
384
- it 'can include a top level errors node' do
384
+ it 'can include a top level errors node - deprecated' do
385
385
  post = create(:post)
386
386
  errors = [
387
387
  {
@@ -400,6 +400,21 @@ describe JSONAPI::Serializer do
400
400
  'data' => serialize_primary(post, {serializer: MyApp::PostSerializer}),
401
401
  })
402
402
  end
403
+ it 'can include a top level errors node' do
404
+ errors = [
405
+ {
406
+ "source" => { "pointer" => "/data/attributes/first-name" },
407
+ "title" => "Invalid Attribute",
408
+ "detail" => "First name must contain at least three characters."
409
+ },
410
+ {
411
+ "source" => { "pointer" => "/data/attributes/first-name" },
412
+ "title" => "Invalid Attribute",
413
+ "detail" => "First name must contain an emoji."
414
+ }
415
+ ]
416
+ expect(JSONAPI::Serializer.serialize_errors(errors)).to eq({'errors' => errors})
417
+ end
403
418
  it 'can serialize a single object with an `each` method by passing skip_collection_check: true' do
404
419
  post = create(:post)
405
420
  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.8.0
4
+ version: 0.9.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: 2016-04-12 00:00:00.000000000 Z
11
+ date: 2016-04-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport