jsonapi-utils 0.7.1 → 0.7.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/README.md +4 -1
- data/lib/jsonapi/utils/response/formatters.rb +4 -0
- data/lib/jsonapi/utils/support/pagination.rb +17 -0
- data/lib/jsonapi/utils/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 81b9858b8125f047d7c6b26ed950d98072c6af8b
|
4
|
+
data.tar.gz: b7436b63bbc441f6592f6ada45cedace0633fa9c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1285cd935d1acab08e5f950290c2eabb744420aeac9312877e856ee1a9a16e0dace61d6797b60ed8b48994e67860fbc2f299c0a2169a48ef1939c9a52565425c
|
7
|
+
data.tar.gz: 9ab8279a639f27b412c8b7aec1857f4c4db9e7f928487950b6118afe6c30c5ecd40b9b97e2035f706e9eea4557d6e5772776dff848ddc424c382e676fc6df999
|
data/README.md
CHANGED
@@ -65,7 +65,7 @@ gem 'jsonapi-utils', '~> 0.4.9'
|
|
65
65
|
For Rails 5:
|
66
66
|
|
67
67
|
```ruby
|
68
|
-
gem 'jsonapi-utils', '~> 0.7.
|
68
|
+
gem 'jsonapi-utils', '~> 0.7.2'
|
69
69
|
```
|
70
70
|
|
71
71
|
And then execute:
|
@@ -464,6 +464,9 @@ JSONAPI.configure do |config|
|
|
464
464
|
config.top_level_meta_include_record_count = true
|
465
465
|
config.top_level_meta_record_count_key = :record_count
|
466
466
|
|
467
|
+
config.top_level_meta_include_page_count = true
|
468
|
+
config.top_level_meta_page_count_key = :page_count
|
469
|
+
|
467
470
|
config.use_text_errors = false
|
468
471
|
|
469
472
|
config.exception_class_whitelist = []
|
@@ -194,6 +194,10 @@ module JSONAPI
|
|
194
194
|
if JSONAPI.configuration.top_level_meta_include_record_count
|
195
195
|
data[:record_count] = record_count_for(records, options)
|
196
196
|
end
|
197
|
+
|
198
|
+
if JSONAPI.configuration.top_level_meta_include_page_count
|
199
|
+
data[:page_count] = page_count_for(data[:record_count])
|
200
|
+
end
|
197
201
|
end
|
198
202
|
end
|
199
203
|
|
@@ -157,6 +157,23 @@ module JSONAPI
|
|
157
157
|
end
|
158
158
|
end
|
159
159
|
|
160
|
+
# Count pages in order to build a proper pagination and to fill up the "page_count" response's member.
|
161
|
+
#
|
162
|
+
# @param record_count [Integer] number of records
|
163
|
+
# e.g.: 42
|
164
|
+
#
|
165
|
+
# @return [Integer]
|
166
|
+
# e.g 5
|
167
|
+
#
|
168
|
+
# @api private
|
169
|
+
def page_count_for(record_count)
|
170
|
+
return 0 if record_count.to_i < 1
|
171
|
+
|
172
|
+
size = (page_params['size'] || page_params['limit']).to_i
|
173
|
+
size = JSONAPI.configuration.default_page_size unless size.nonzero?
|
174
|
+
(record_count.to_f / size).ceil
|
175
|
+
end
|
176
|
+
|
160
177
|
# Count records from the datatase applying the given request filters
|
161
178
|
# and skipping things like eager loading, grouping and sorting.
|
162
179
|
#
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jsonapi-utils
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.7.
|
4
|
+
version: 0.7.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tiago Guedes
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: exe
|
11
11
|
cert_chain: []
|
12
|
-
date: 2018-
|
12
|
+
date: 2018-04-25 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: jsonapi-resources
|