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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 916d37b9e745362ffe32ecb2714d9a3189bdf42ff25b5003418b0322fd8f13c3
4
- data.tar.gz: 50802e7b49a6d5fb1cec608971081f8780068190a7c444ea1d34b4e212a5cc2b
3
+ metadata.gz: bdbcdbae0d050e594266eeb3a84ee99ac64ca19febc7ba1d86d823479e832f0d
4
+ data.tar.gz: 6c5bafdb777e5f5722c0ce14cd2e6978bd727409b9a09ea1e68c5ecc07671434
5
5
  SHA512:
6
- metadata.gz: e3889bbacc408251a944c9950f3cb4dd7eae46e6f12c66b422c67bf33ce60dde0d45c95db318f492a16a12a9606b731167607a10b516cb74fe40fd25d4d14632
7
- data.tar.gz: 2e096623acc9d4cc1ba48bb5c0f1c6364253ccd1d81cfabe73832a8ecfaba21c8197d61a5d90627fd66a374d1255961dcdc7125ba691c6bbd78af7e6655bff4a
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") && (parameters.fetch("page").key?("limit") || parameters.fetch("page").key?("offset"))
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.is_a?(Array)
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"))]
@@ -2,6 +2,6 @@
2
2
 
3
3
  module JSONAPI
4
4
  module Realizer
5
- VERSION = "6.2.1"
5
+ VERSION = "6.2.3"
6
6
  end
7
7
  end
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.1
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-18 00:00:00.000000000 Z
11
+ date: 2023-10-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport