next_page 0.1.7 → 0.1.8

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 91b9a69827f83cb0e3fd5dcbbdab8537c61d859f89cea744a2afccf8afcf3570
4
- data.tar.gz: 4474b5cdb0d3e44473df17a0ae10fbd389abf9a3e372062f5691fb656c8a21e4
3
+ metadata.gz: b3a633fa748d4bdcff2576c514993b13373a95d999680ef06ef0439ba9f849c3
4
+ data.tar.gz: 58f4616e60f4fe84583a03efe134eac635cf19fee0d5da85c99d9790203cdfc3
5
5
  SHA512:
6
- metadata.gz: bf4b093bb8ae31e75c83416539bd3b9848956e81ff90fcecfd0ed90c08cfdbaf6f84e55651130f6115b3c070f77c0d46a336ce95e74bd785f8a0cd20b5d6dba6
7
- data.tar.gz: b0d3559fc5db3431acf8102471db073e17fc428bd8bfc05bbf1b8f472547d4686b9da0eaed4872e9313b0c3d2600ae58f28b933b23732646d3027c1206fd3ac0
6
+ metadata.gz: d91211f3d61c31c98ec05b8512fc0a277ad13490f654c272b5ec77fd1539cc83f6c17bd87169b18a4d66b8a713237da6858543cda2d45bf6041e3c145c4ecd20
7
+ data.tar.gz: 9617247dbad11b9ef5ef083f489728c565a901e632d77a59c184d25ae0ea48d3e55cf4dbd1e9f30a8e1d7c089dd7616822f786b5bebb21d245ea9890364a3fea
data/README.md CHANGED
@@ -1,5 +1,6 @@
1
1
  [![Gem Version](https://badge.fury.io/rb/next_page.svg)](https://badge.fury.io/rb/next_page)
2
2
  [![RuboCop](https://github.com/RockSolt/next_page/workflows/RuboCop/badge.svg)](https://github.com/RockSolt/next_page/actions?query=workflow%3ARuboCop)
3
+ [![Maintainability](https://api.codeclimate.com/v1/badges/0efe1a9b66a0bf161536/maintainability)](https://codeclimate.com/github/RockSolt/next_page/maintainability)
3
4
 
4
5
  # NextPage
5
6
  Basic pagination for Rails controllers.
@@ -3,8 +3,8 @@
3
3
  module NextPage
4
4
  # = Pagination Attributes
5
5
  #
6
- # Module PaginationAttributes adds in methods required for pagination links: current_page, next_page, and total_pages.
7
- # It reads the offset and limit on the query to determine the values.
6
+ # Module PaginationAttributes adds in methods required for pagination links: previous_page, current_page, next_page,
7
+ # and total_pages. It reads the offset and limit on the query to determine the values.
8
8
  #
9
9
  # In some cases the query will not support count. In that case, there are two ways to override the default behavior:
10
10
  # - provide a count_query that can resolve the attributes
@@ -12,12 +12,16 @@ module NextPage
12
12
  module PaginationAttributes
13
13
  attr_writer :count_query, :current_page, :total_count, :per_page
14
14
 
15
+ def previous_page
16
+ current_page > 1 ? current_page - 1 : nil
17
+ end
18
+
15
19
  def current_page
16
- @current_page ||= count_query.offset_value + 1
20
+ @current_page ||= (count_query.offset_value || 0) + 1
17
21
  end
18
22
 
19
23
  def next_page
20
- current_page + 1
24
+ total_pages > current_page ? current_page + 1 : nil
21
25
  end
22
26
 
23
27
  def total_count
@@ -1,3 +1,3 @@
1
1
  module NextPage
2
- VERSION = '0.1.7'
2
+ VERSION = '0.1.8'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: next_page
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.7
4
+ version: 0.1.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Todd Kummer
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-08-12 00:00:00.000000000 Z
11
+ date: 2021-02-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -16,7 +16,7 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: 6.0.2
19
+ version: '6.0'
20
20
  - - ">="
21
21
  - !ruby/object:Gem::Version
22
22
  version: 6.0.2.2
@@ -26,7 +26,7 @@ dependencies:
26
26
  requirements:
27
27
  - - "~>"
28
28
  - !ruby/object:Gem::Version
29
- version: 6.0.2
29
+ version: '6.0'
30
30
  - - ">="
31
31
  - !ruby/object:Gem::Version
32
32
  version: 6.0.2.2