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 +4 -4
- data/lib/railsful/deserializer.rb +20 -9
- data/lib/railsful/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 30e8f5c72f7b2752718a8d4724c28b5852f8dd8e5aaac4c206f8309a63cc34e8
|
4
|
+
data.tar.gz: 0c74fe0fe436cdf061a8c86d54a007718dcffd7863681458bed90c4b2bb9d35a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
-
|
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
|
-
|
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
|
-
|
42
|
+
attrs.merge!(relationship(type, payload))
|
30
43
|
end
|
31
44
|
|
32
|
-
|
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
|
|
data/lib/railsful/version.rb
CHANGED