jsonapi_parameters 0.3.2 → 0.3.3

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
  SHA256:
3
- metadata.gz: 2c5168b902ba06254205cb268d65804bf0d4630d5c9dd98a03f71eee9ac4d5ec
4
- data.tar.gz: 67eae506d68b36a8ce3d788464ac11c3d7c823621229d0b8c142f00522ade30e
3
+ metadata.gz: fd088c3d78576a1a35f884af0a1ce64e8a9616c50038e6fac7ad64dee1cac3de
4
+ data.tar.gz: 8b1e5a6fe237922ababfd50c0d51e50c039a42c1fc0750af2972a631b73bf13e
5
5
  SHA512:
6
- metadata.gz: 2c37d85e4a9f2ad6bac170763aa82cc13dbd73b78bb25340c181745adbc3d8f3c117d29a71ff1d10072d2fffaa79f21eab13820f731810c8df52cd679626d294
7
- data.tar.gz: 070c5e18602327f4e1b8df6cd93d1f7f7cf87aee653c828384b93098d552d64e4ba6af34fc27785f19e3c758085e7b97c4a395f228ddb12628be722eae18d05e
6
+ metadata.gz: 15cd4a6231720e0bc2d34b83e531a5bec95610638e5f3af80815730c5e414b2b9a22ea12c64685cf30698eae6899ba35dbf241b718f58dfedda5603dc4b97cf5
7
+ data.tar.gz: 3a6b5ebfa7562b27a34779f8db849dcf3233b9739112b02d71384a05af178eb1dc7392456db2ea4fc808348a0b6f6e4f63a4329df002f305b899c4b1e0c6c8ec
@@ -35,12 +35,13 @@ module JsonApi::Parameters
35
35
  jsonapi_unsafe_params.tap do |param|
36
36
  jsonapi_relationships.each do |relationship_key, relationship_value|
37
37
  relationship_value = relationship_value[:data]
38
-
39
38
  key, val = case relationship_value
40
39
  when Array
41
40
  handle_to_many_relation(relationship_key, relationship_value)
42
41
  when Hash
43
42
  handle_to_one_relation(relationship_key, relationship_value)
43
+ when nil
44
+ handle_nil_relation(relationship_key)
44
45
  else
45
46
  raise jsonapi_not_implemented_err
46
47
  end
@@ -114,6 +115,14 @@ module JsonApi::Parameters
114
115
  ["#{singularize(relationship_key)}_attributes".to_sym, included_object]
115
116
  end
116
117
 
118
+ def handle_nil_relation(relationship_key)
119
+ # Graceful fail if nil on to-many association.
120
+ raise jsonapi_not_implemented_err if pluralize(relationship_key).to_sym == relationship_key
121
+
122
+ # Handle with empty hash.
123
+ handle_to_one_relation(relationship_key, {})
124
+ end
125
+
117
126
  def find_included_object(related_id:, related_type:)
118
127
  jsonapi_included.find do |included_object_enum|
119
128
  included_object_enum[:id] &&
@@ -1,5 +1,5 @@
1
1
  module JsonApi
2
2
  module Parameters
3
- VERSION = '0.3.2'.freeze
3
+ VERSION = '0.3.3'.freeze
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jsonapi_parameters
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.2
4
+ version: 0.3.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Visuality
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2019-08-28 00:00:00.000000000 Z
12
+ date: 2019-10-21 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activesupport