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: 7bdeb10cf2422e9d7834c72348a2f3e76be9f88d
4
- data.tar.gz: fdae6a01e86e5d555230e9eabcbe5a506e53c2e9
3
+ metadata.gz: f12aa45a3ed7366d2713012deb98b6090c4ac2f6
4
+ data.tar.gz: 43c9dfa94e247474e2270ae1656cafcb8157cee9
5
5
  SHA512:
6
- metadata.gz: f579940ad3a9ebe2a10a0bd51c7b53759f9d3648754efc5f5b7534fd18ec898ad7860bdfa7ed9fd684a033e25ccad3d5a452d73ea7c918af30b2958ea71f6fd2
7
- data.tar.gz: 14ff1076e0f0a4c474e0ac3bfdef84288ce1b6bdfbce315ed7e921a0ebcae621b94902aef7871912114bf728e72d2b088655e6682604ba62206303cf50ac9782
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
- pagination_evaluator.call(limit: limit, offset: offset + limit)
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
 
@@ -1,3 +1,3 @@
1
1
  module PragmaticSerializer
2
- VERSION = "0.3.0"
2
+ VERSION = "0.3.1"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pragmatic_serializer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tomas Valent