jsonapi-resources 0.10.6 → 0.10.7
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/jsonapi/paginator.rb +17 -0
- data/lib/jsonapi/processor.rb +15 -7
- data/lib/jsonapi/resources/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: d30a2ea26f6bb9f907e0710a7e9d95a9682bfa64ab0fd7ae1e5b350c07f52924
|
4
|
+
data.tar.gz: fd883de5a6506f4aaad03fcf3ec61ec311c0e57f0cf33ea8c3d8b082c47b2671
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cc53b7071fb93b2f2f5c8ff2f02b43572a56d5da8a58835cff73953100db55c0ea9dbc2a1d26b7b06ae854d8e588276619d7631a4dc509e7c6332b9ced5c6245
|
7
|
+
data.tar.gz: d9f77c39f058f3978b20ccba5d2beea4744bbda9cb1b19933ed9a3a235a5265a9fecb945a2fd3646f0135cb97059896be3ac2fa19023a94fd555480ac8483f95
|
data/lib/jsonapi/paginator.rb
CHANGED
@@ -13,9 +13,16 @@ module JSONAPI
|
|
13
13
|
# :nocov:
|
14
14
|
end
|
15
15
|
|
16
|
+
def requires_record_count
|
17
|
+
# :nocov:
|
18
|
+
self.class.requires_record_count
|
19
|
+
# :nocov:
|
20
|
+
end
|
21
|
+
|
16
22
|
class << self
|
17
23
|
def requires_record_count
|
18
24
|
# :nocov:
|
25
|
+
# @deprecated
|
19
26
|
false
|
20
27
|
# :nocov:
|
21
28
|
end
|
@@ -36,10 +43,15 @@ class OffsetPaginator < JSONAPI::Paginator
|
|
36
43
|
verify_pagination_params
|
37
44
|
end
|
38
45
|
|
46
|
+
# @deprecated
|
39
47
|
def self.requires_record_count
|
40
48
|
true
|
41
49
|
end
|
42
50
|
|
51
|
+
def requires_record_count
|
52
|
+
true
|
53
|
+
end
|
54
|
+
|
43
55
|
def apply(relation, _order_options)
|
44
56
|
relation.offset(@offset).limit(@limit)
|
45
57
|
end
|
@@ -127,10 +139,15 @@ class PagedPaginator < JSONAPI::Paginator
|
|
127
139
|
verify_pagination_params
|
128
140
|
end
|
129
141
|
|
142
|
+
# @deprecated
|
130
143
|
def self.requires_record_count
|
131
144
|
true
|
132
145
|
end
|
133
146
|
|
147
|
+
def requires_record_count
|
148
|
+
true
|
149
|
+
end
|
150
|
+
|
134
151
|
def calculate_page_count(record_count)
|
135
152
|
(record_count / @size.to_f).ceil
|
136
153
|
end
|
data/lib/jsonapi/processor.rb
CHANGED
@@ -65,13 +65,13 @@ module JSONAPI
|
|
65
65
|
resource_set.populate!(serializer, context, find_options)
|
66
66
|
|
67
67
|
page_options = result_options
|
68
|
-
if (
|
68
|
+
if (top_level_meta_include_record_count || (paginator && paginator.requires_record_count))
|
69
69
|
page_options[:record_count] = resource_klass.count(verified_filters,
|
70
70
|
context: context,
|
71
71
|
include_directives: include_directives)
|
72
72
|
end
|
73
73
|
|
74
|
-
if (
|
74
|
+
if (top_level_meta_include_page_count && paginator && page_options[:record_count])
|
75
75
|
page_options[:page_count] = paginator ? paginator.calculate_page_count(page_options[:record_count]) : 1
|
76
76
|
end
|
77
77
|
|
@@ -197,9 +197,9 @@ module JSONAPI
|
|
197
197
|
resource_set.populate!(serializer, context, find_options)
|
198
198
|
|
199
199
|
opts = result_options
|
200
|
-
if ((
|
201
|
-
(paginator && paginator.
|
202
|
-
(
|
200
|
+
if ((top_level_meta_include_record_count) ||
|
201
|
+
(paginator && paginator.requires_record_count) ||
|
202
|
+
(top_level_meta_include_page_count))
|
203
203
|
|
204
204
|
opts[:record_count] = source_resource.class.count_related(
|
205
205
|
source_resource.identity,
|
@@ -207,13 +207,13 @@ module JSONAPI
|
|
207
207
|
find_options)
|
208
208
|
end
|
209
209
|
|
210
|
-
if (
|
210
|
+
if (top_level_meta_include_page_count && opts[:record_count])
|
211
211
|
opts[:page_count] = paginator.calculate_page_count(opts[:record_count])
|
212
212
|
end
|
213
213
|
|
214
214
|
opts[:pagination_params] = if paginator && JSONAPI.configuration.top_level_links_include_pagination
|
215
215
|
page_options = {}
|
216
|
-
page_options[:record_count] = opts[:record_count] if paginator.
|
216
|
+
page_options[:record_count] = opts[:record_count] if paginator.requires_record_count
|
217
217
|
paginator.links_page_params(page_options.merge(fetched_resources: resource_set))
|
218
218
|
else
|
219
219
|
{}
|
@@ -382,6 +382,14 @@ module JSONAPI
|
|
382
382
|
JSONAPI::ResourceSet.new(resource_id_tree)
|
383
383
|
end
|
384
384
|
|
385
|
+
def top_level_meta_include_record_count
|
386
|
+
JSONAPI.configuration.top_level_meta_include_record_count
|
387
|
+
end
|
388
|
+
|
389
|
+
def top_level_meta_include_page_count
|
390
|
+
JSONAPI.configuration.top_level_meta_include_page_count
|
391
|
+
end
|
392
|
+
|
385
393
|
private
|
386
394
|
def find_related_resource_id_tree(resource_klass, source_id, relationship_name, find_options, include_related)
|
387
395
|
options = find_options.except(:include_directives)
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jsonapi-resources
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.10.
|
4
|
+
version: 0.10.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dan Gebhardt
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2022-
|
12
|
+
date: 2022-03-09 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|