pragmatic_serializer 0.3.0 → 0.3.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: f12aa45a3ed7366d2713012deb98b6090c4ac2f6
|
4
|
+
data.tar.gz: 43c9dfa94e247474e2270ae1656cafcb8157cee9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 379215fc4220f598c6f05c84237e3515d3c4bb7d34c1f9d600ad5b3b180685b4932d5f4154f9e87b9ee492cb3095567c86765203df017cca29e8a917b926c994
|
7
|
+
data.tar.gz: 18a42d4c24d04dd09e3fd7d943c07852b6a781404c5b74af3af55ecaaefa396cfdaa6293e5e6dbe0483bea67452f2d6d20aec5197ac50f9eb14c8ede643f94e4
|
@@ -6,7 +6,7 @@ module PragmaticSerializer
|
|
6
6
|
include PragmaticSerializer::ConfigInterface
|
7
7
|
|
8
8
|
attr_writer :limit, :offset, :serialization_method, :resource_options
|
9
|
-
attr_accessor :resources, :resource_serializer, :pagination_evaluator
|
9
|
+
attr_accessor :resources, :total, :resource_serializer, :pagination_evaluator
|
10
10
|
|
11
11
|
def serialization_method
|
12
12
|
@serialization_method ||= config.default_resource_serialization_method
|
@@ -51,6 +51,7 @@ module PragmaticSerializer
|
|
51
51
|
@pagination_json ||= PragmaticSerializer::PaginationJSON.new({
|
52
52
|
limit: limit,
|
53
53
|
offset: offset,
|
54
|
+
total: total,
|
54
55
|
pagination_evaluator: pagination_evaluator
|
55
56
|
})
|
56
57
|
end
|
@@ -1,10 +1,11 @@
|
|
1
1
|
module PragmaticSerializer
|
2
2
|
class PaginationJSON
|
3
|
-
attr_reader :limit, :offset, :pagination_evaluator
|
3
|
+
attr_reader :limit, :offset, :total, :pagination_evaluator
|
4
4
|
|
5
|
-
def initialize(limit:, offset:, pagination_evaluator:)
|
5
|
+
def initialize(limit:, offset:, total: nil, pagination_evaluator:)
|
6
6
|
@limit = limit
|
7
7
|
@offset = offset
|
8
|
+
@total = total
|
8
9
|
@pagination_evaluator = pagination_evaluator
|
9
10
|
end
|
10
11
|
|
@@ -24,11 +25,17 @@ module PragmaticSerializer
|
|
24
25
|
end
|
25
26
|
|
26
27
|
def next
|
27
|
-
|
28
|
+
show_next = unless total.nil?
|
29
|
+
total > (offset + limit)
|
30
|
+
else
|
31
|
+
true
|
32
|
+
end
|
33
|
+
|
34
|
+
pagination_evaluator.call(limit: limit, offset: offset + limit) if show_next
|
28
35
|
end
|
29
36
|
|
30
37
|
def prev
|
31
|
-
prev_offset = offset < limit ? 0 : offset - limit
|
38
|
+
prev_offset = offset < limit ? 0 : offset - limit
|
32
39
|
pagination_evaluator.call(limit: limit, offset: prev_offset) if offset > 0
|
33
40
|
end
|
34
41
|
|