active_model_serializers_contrib 0.2.0 → 0.2.1
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
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1b61b65aa8a796fa7afb871efe66fc1cefa0850d
|
4
|
+
data.tar.gz: f6c0ce27e873c094f98764633816b22674e4c106
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d1c54bb662204a3f3c4f6b3b60313cd080dd2c113af5a60de3d201c6de3e2dde0c6a4287bae903db4257768a88a867610e65581bd8e379c2e872b776827605a2
|
7
|
+
data.tar.gz: bdcb336a79c41f90b42886329d1dabbd91c1a14a870d83f87961dd5b635815ae17138fdac2e7922c81a574c88db3b632b8af241367d549c67a3e81d323f5e0f9
|
@@ -4,7 +4,7 @@ class ActiveModel::PaginationSerializer < ActiveModel::ArraySerializer
|
|
4
4
|
per_page = object.limit_value
|
5
5
|
offset = object.offset_value
|
6
6
|
current_page = offset ? (offset / per_page) + 1 : 1
|
7
|
-
total_items = object
|
7
|
+
total_items = item_count(object)
|
8
8
|
total_pages = per_page ? (total_items / per_page.to_f).ceil : 1
|
9
9
|
prev_page = current_page - 1
|
10
10
|
prev_page = nil if prev_page < 1
|
@@ -24,4 +24,12 @@ class ActiveModel::PaginationSerializer < ActiveModel::ArraySerializer
|
|
24
24
|
|
25
25
|
alias_method_chain :initialize, :pagination
|
26
26
|
|
27
|
+
private
|
28
|
+
|
29
|
+
def item_count(object)
|
30
|
+
initial_count = object.limit(nil).offset(nil).count(:all)
|
31
|
+
|
32
|
+
(initial_count.respond_to? :count) ? initial_count.count : initial_count
|
33
|
+
end
|
34
|
+
|
27
35
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: active_model_serializers_contrib
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- G5
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2016-
|
12
|
+
date: 2016-08-22 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: active_model_serializers
|
@@ -158,7 +158,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
158
158
|
version: '0'
|
159
159
|
requirements: []
|
160
160
|
rubyforge_project:
|
161
|
-
rubygems_version: 2.
|
161
|
+
rubygems_version: 2.5.1
|
162
162
|
signing_key:
|
163
163
|
specification_version: 4
|
164
164
|
summary: Modules/classes that extend AMS with more functionality
|