railsful 0.1.1 → 0.1.2

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
  SHA256:
3
- metadata.gz: 579c6c21ef0b0e65a53d5449bb1ac7863670f20941a93e79d474eed2ca2d80b2
4
- data.tar.gz: b9cb7322dfe0b08d636c481197ed2897ef021a1fa794165c0fc4631309e02d4a
3
+ metadata.gz: 30e8f5c72f7b2752718a8d4724c28b5852f8dd8e5aaac4c206f8309a63cc34e8
4
+ data.tar.gz: 0c74fe0fe436cdf061a8c86d54a007718dcffd7863681458bed90c4b2bb9d35a
5
5
  SHA512:
6
- metadata.gz: 162cfe70d4b921ad3a8c9a3ec92161abf29e792bbc055583234f1e2570c5b84d2ee578012776a871e3898f3f89bfa36415a231956f6bbc4e944232f38d8ae4d5
7
- data.tar.gz: 20ef9a433fe1594c3dd06912cf53ae8a0c5ac299dadc051e80fa46e262fbc99ecd60b0e3b70bb421ca8dbac7dd486bc58160833871ffa6ee73a2a075160a4b7b
6
+ metadata.gz: c0fb4853f6763cdabfe55a4799ba1647055f658e71c60b40fe7026b3d782b1140c3f289e443b93160089423a8131722cccf91dc2ebd82efd67ee3552764e2cec
7
+ data.tar.gz: c39bed75213fdc2b6651474491c43777e6937fc36133e696cdde1b65296106561dc8b4d84bd7a436e40b8156141744fde9a7c379505b1e2553a1d8cee10e6aff
@@ -17,27 +17,38 @@ module Railsful
17
17
  #
18
18
  # :reek:FeatureEnvy
19
19
  def deserialize
20
- deserialized = {}
20
+ # Fetch attributes including resource id.
21
+ deserialized = attributes(params)
21
22
 
23
+ # Get the included elements.
24
+ deserialized.deeper_merge!(included_hash(params))
25
+
26
+ # Return the deserialized params.
27
+ ActionController::Parameters.new(deserialized)
28
+ end
29
+
30
+ # First level attributes from data object.
31
+ #
32
+ # :reek:FeatureEnvy
33
+ def attributes(params)
22
34
  data = params.fetch(:data, {})
23
35
 
24
- # Merge the resources attributes
25
- deserialized.merge!(data.fetch(:attributes, {}))
36
+ # Merge the resources attributes. Also merge the id since jsonapi does
37
+ # not allow ids in the attribute body.
38
+ attrs = data.fetch(:attributes, {}).merge(id: data[:id])
26
39
 
27
40
  # Get the already existing relationships
28
41
  data.fetch(:relationships, {}).each do |type, payload|
29
- deserialized.merge!(relationship(type, payload))
42
+ attrs.merge!(relationship(type, payload))
30
43
  end
31
44
 
32
- # Get the included elements.
33
- deserialized.deeper_merge!(included_hash(params))
34
-
35
- # Return the deserialized params.
36
- ActionController::Parameters.new(deserialized)
45
+ attrs.compact
37
46
  end
38
47
 
39
48
  # Fetches all included associations/relationships from the
40
49
  # included hash.
50
+ #
51
+ # :reek:UtilityFunction
41
52
  def included_hash(params)
42
53
  included_hash = {}
43
54
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Railsful
4
- VERSION = '0.1.1'.freeze
4
+ VERSION = '0.1.2'.freeze
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: railsful
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Henning Vogt