jsonapi-realizer 6.2.1 → 6.2.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/jsonapi/realizer/action.rb +4 -2
- data/lib/jsonapi/realizer/resource.rb +19 -11
- data/lib/jsonapi/realizer/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bdbcdbae0d050e594266eeb3a84ee99ac64ca19febc7ba1d86d823479e832f0d
|
4
|
+
data.tar.gz: 6c5bafdb777e5f5722c0ce14cd2e6978bd727409b9a09ea1e68c5ecc07671434
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1b3c4810879476f7d3d748a16a8538c599f3e288cb7aa55d83bacb7727eb9abc135e12afd9140b6650cd062e8629b6cbf307f655c3fcecaa20bbd71db3299e9b
|
7
|
+
data.tar.gz: 40eeabceb511afea21c0baab9c840c9963ba05a6b3c286b2464a80391e8d3ebe71e700e78ca7b0ecc99fe1105eab090f970983a601e61bf17444414e0366dd0c
|
@@ -123,18 +123,20 @@ module JSONAPI
|
|
123
123
|
|
124
124
|
private def attributes
|
125
125
|
return unless data
|
126
|
+
return {} unless data["attributes"].kind_of?(Hash)
|
126
127
|
|
127
128
|
data
|
128
|
-
.fetch("attributes"
|
129
|
+
.fetch("attributes")
|
129
130
|
.transform_keys(&:underscore)
|
130
131
|
.select(&resource_class.method(:valid_attribute?))
|
131
132
|
end
|
132
133
|
|
133
134
|
private def relationships
|
134
135
|
return unless data
|
136
|
+
return {} unless data["relationships"].kind_of?(Hash)
|
135
137
|
|
136
138
|
data
|
137
|
-
.fetch("relationships"
|
139
|
+
.fetch("relationships")
|
138
140
|
.transform_keys(&:underscore)
|
139
141
|
.select(&resource_class.method(:valid_relationship?))
|
140
142
|
.transform_values(&method(:as_relationship))
|
@@ -73,7 +73,15 @@ module JSONAPI
|
|
73
73
|
end
|
74
74
|
|
75
75
|
def paginate?
|
76
|
-
parameters.key?("page") &&
|
76
|
+
parameters.key?("page") && parameters.fetch("page").respond_to?(:fetch) && (paginate_limit? || paginate_offset?)
|
77
|
+
end
|
78
|
+
|
79
|
+
private def paginate_limit?
|
80
|
+
parameters.fetch("page").key?("limit")
|
81
|
+
end
|
82
|
+
|
83
|
+
private def paginate_offset?
|
84
|
+
parameters.fetch("page").key?("offset")
|
77
85
|
end
|
78
86
|
|
79
87
|
def pagination
|
@@ -84,7 +92,7 @@ module JSONAPI
|
|
84
92
|
end
|
85
93
|
|
86
94
|
def sorting?
|
87
|
-
parameters.key?("sort")
|
95
|
+
parameters.key?("sort") && parameters.fetch("sort").respond_to?(:split)
|
88
96
|
end
|
89
97
|
|
90
98
|
def sorts
|
@@ -105,7 +113,7 @@ module JSONAPI
|
|
105
113
|
end
|
106
114
|
|
107
115
|
def filtering?
|
108
|
-
parameters.key?("filter")
|
116
|
+
parameters.key?("filter") && parameters.fetch("filter").respond_to?(:transform_keys)
|
109
117
|
end
|
110
118
|
|
111
119
|
def filters
|
@@ -118,7 +126,7 @@ module JSONAPI
|
|
118
126
|
end
|
119
127
|
|
120
128
|
def include?
|
121
|
-
parameters.key?("include")
|
129
|
+
parameters.key?("include") && parameters.fetch("include").respond_to?(:split)
|
122
130
|
end
|
123
131
|
|
124
132
|
def includes
|
@@ -150,7 +158,7 @@ module JSONAPI
|
|
150
158
|
end
|
151
159
|
|
152
160
|
def selects?
|
153
|
-
parameters.key?("fields")
|
161
|
+
parameters.key?("fields") && parameters.fetch("fields").respond_to?(:transform_keys)
|
154
162
|
end
|
155
163
|
|
156
164
|
def selects
|
@@ -168,14 +176,14 @@ module JSONAPI
|
|
168
176
|
|
169
177
|
def attributes
|
170
178
|
@attributes ||= data
|
171
|
-
.fetch("attributes"
|
179
|
+
.fetch("attributes")
|
172
180
|
.transform_keys(&:underscore)
|
173
181
|
.transform_keys { |key| attribute(key).as }
|
174
182
|
end
|
175
183
|
|
176
184
|
def relationships
|
177
185
|
@relationships ||= data
|
178
|
-
.fetch("relationships"
|
186
|
+
.fetch("relationships")
|
179
187
|
.transform_keys(&:underscore)
|
180
188
|
.map(&method(:as_relationship)).to_h
|
181
189
|
.transform_keys { |key| relation(key).as }
|
@@ -281,7 +289,7 @@ module JSONAPI
|
|
281
289
|
end
|
282
290
|
|
283
291
|
private def data?
|
284
|
-
parameters.key?("data")
|
292
|
+
parameters.key?("data") && (parameters.fetch("data").respond_to?(:fetch) || parameters.fetch("data").respond_to?(:map))
|
285
293
|
end
|
286
294
|
|
287
295
|
private def data
|
@@ -295,11 +303,11 @@ module JSONAPI
|
|
295
303
|
end
|
296
304
|
|
297
305
|
private def attributes?
|
298
|
-
data.key?("attributes")
|
306
|
+
data.key?("attributes") && data.fetch("attributes").respond_to?(:fetch)
|
299
307
|
end
|
300
308
|
|
301
309
|
private def relationships?
|
302
|
-
data.key?("relationships")
|
310
|
+
data.key?("relationships") && data.fetch("relationships").respond_to?(:fetch)
|
303
311
|
end
|
304
312
|
|
305
313
|
private def scope
|
@@ -313,7 +321,7 @@ module JSONAPI
|
|
313
321
|
|
314
322
|
relation_configuration = relation(name).realizer_class.configuration
|
315
323
|
|
316
|
-
if data.
|
324
|
+
if data.kind_of?(Array)
|
317
325
|
[name, relation_configuration.adapter.find_many(relation_configuration.model_class, { id: data.map { |value| value.fetch("id") } })]
|
318
326
|
else
|
319
327
|
[name, relation_configuration.adapter.find_one(relation_configuration.model_class, data.fetch("id"))]
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jsonapi-realizer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 6.2.
|
4
|
+
version: 6.2.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kurtis Rainbolt-Greene
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-10-
|
11
|
+
date: 2023-10-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|