railsful 0.1.0 → 0.1.1
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/.gitignore +2 -0
- data/lib/railsful/deserializer.rb +15 -4
- data/lib/railsful/version.rb +1 -1
- data/railsful.gemspec +3 -3
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 579c6c21ef0b0e65a53d5449bb1ac7863670f20941a93e79d474eed2ca2d80b2
|
4
|
+
data.tar.gz: b9cb7322dfe0b08d636c481197ed2897ef021a1fa794165c0fc4631309e02d4a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 162cfe70d4b921ad3a8c9a3ec92161abf29e792bbc055583234f1e2570c5b84d2ee578012776a871e3898f3f89bfa36415a231956f6bbc4e944232f38d8ae4d5
|
7
|
+
data.tar.gz: 20ef9a433fe1594c3dd06912cf53ae8a0c5ac299dadc051e80fa46e262fbc99ecd60b0e3b70bb421ca8dbac7dd486bc58160833871ffa6ee73a2a075160a4b7b
|
data/.gitignore
CHANGED
@@ -1,8 +1,11 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require 'deep_merge/rails_compat'
|
4
|
+
require 'active_support/inflector'
|
4
5
|
|
5
6
|
module Railsful
|
7
|
+
# The deserializer class handles the "unwrapping" of incoming parameters.
|
8
|
+
# It translates jsonapi compliant params to those that Rails understands.
|
6
9
|
class Deserializer
|
7
10
|
attr_reader :params
|
8
11
|
|
@@ -43,11 +46,19 @@ module Railsful
|
|
43
46
|
attrs = inc[:attributes]
|
44
47
|
|
45
48
|
if params.dig(:data, :relationships, type, :data).is_a?(Array)
|
46
|
-
#
|
47
|
-
|
48
|
-
|
49
|
+
# We pluralize the type since we are dealing with a
|
50
|
+
# +has_many+ relationship.
|
51
|
+
plural = ActiveSupport::Inflector.pluralize(type)
|
52
|
+
|
53
|
+
included_hash["#{plural}_attributes"] ||= []
|
54
|
+
included_hash["#{plural}_attributes"] << attrs
|
49
55
|
else
|
50
|
-
|
56
|
+
# When the data value is not an Array we are assuming that we
|
57
|
+
# deal with a +has_one+ association. To be on the safe side we also
|
58
|
+
# call singularize on the type.
|
59
|
+
singular = ActiveSupport::Inflector.singularize(type)
|
60
|
+
|
61
|
+
included_hash["#{singular}_attributes"] = attrs
|
51
62
|
end
|
52
63
|
end
|
53
64
|
|
data/lib/railsful/version.rb
CHANGED
data/railsful.gemspec
CHANGED
@@ -10,9 +10,9 @@ Gem::Specification.new do |spec|
|
|
10
10
|
'marcus.geissler@hausgold.de']
|
11
11
|
|
12
12
|
spec.summary = 'JSON API serializer and deserializer for Rails'
|
13
|
-
spec.description = 'This gem provides useful helper functions to
|
14
|
-
'with JSON API.'
|
15
|
-
spec.homepage = 'https://github.com/hausgold/
|
13
|
+
spec.description = 'This gem provides useful helper functions to ' \
|
14
|
+
'interaact with JSON API.'
|
15
|
+
spec.homepage = 'https://github.com/hausgold/railsful'
|
16
16
|
spec.license = 'MIT'
|
17
17
|
|
18
18
|
if spec.respond_to?(:metadata)
|
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.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Henning Vogt
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: exe
|
11
11
|
cert_chain: []
|
12
|
-
date: 2019-01-
|
12
|
+
date: 2019-01-16 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: deep_merge
|
@@ -121,7 +121,7 @@ dependencies:
|
|
121
121
|
- - "~>"
|
122
122
|
- !ruby/object:Gem::Version
|
123
123
|
version: '0.15'
|
124
|
-
description: This gem provides useful helper functions to
|
124
|
+
description: This gem provides useful helper functions to interaact with JSON API.
|
125
125
|
email:
|
126
126
|
- henning.vogt@hausgold.de
|
127
127
|
- marcus.geissler@hausgold.de
|
@@ -152,7 +152,7 @@ files:
|
|
152
152
|
- lib/railsful/serializer.rb
|
153
153
|
- lib/railsful/version.rb
|
154
154
|
- railsful.gemspec
|
155
|
-
homepage: https://github.com/hausgold/
|
155
|
+
homepage: https://github.com/hausgold/railsful
|
156
156
|
licenses:
|
157
157
|
- MIT
|
158
158
|
metadata:
|