pageturner 2.0.0 → 3.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +7 -0
- data/README.md +29 -12
- data/lib/pageturner.rb +4 -6
- data/pageturner.gemspec +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: ef072fcfdb860880f1bc64576edc8d19660b0f4a
|
4
|
+
data.tar.gz: 733fa952412342474a7055a5bfc1bf9eb25658c6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 62ae914ea2acd998b3997da0601582cc148d43f97aae635ac7231f7e6efca0014698a11b5407dbc92bc8a948b0c2bf2370aa8769997ef5c77268252bb5685bcf
|
7
|
+
data.tar.gz: 453d69ab87fc3166623a16608da51c44c774343eea3af15452a82fd5c04b39e84b451d4a0a9065f41e5f98afa33f1b5f05aa5042b0695a56bd17769ce228c772
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,10 @@
|
|
1
|
+
# v3.0.0
|
2
|
+
|
3
|
+
## Backwards Incompatible Changes
|
4
|
+
|
5
|
+
* https://github.com/crzrcn/pageturner/commit/eec35955cd273f8fa3fe35ae574cc70a7e775293 - Remove the concern of the next page's URL. Only the application that uses Pageturner has complete knowledge about the URLs that form each page of resources. Pageturner should only be concerned with pagination state. Pageturner will now expose the next page's cursor to achieve this.
|
6
|
+
* Removes `#next_page` in favor of `#next_cursor`. `#next_cursor` returns pagination state that the application can use to create the next page's URL.
|
7
|
+
|
1
8
|
# v2.0.0
|
2
9
|
|
3
10
|
## Backwards Incompatible Changes
|
data/README.md
CHANGED
@@ -15,15 +15,14 @@ query = Model.where(params[:filters])
|
|
15
15
|
anchor_value: params[:last_value],
|
16
16
|
ar_relation: query,
|
17
17
|
sort_direction: Pageturner::DESC,
|
18
|
-
page_size: 25
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
end
|
18
|
+
page_size: 25
|
19
|
+
)
|
20
|
+
|
21
|
+
@next_path = model_path(
|
22
|
+
anchor_column: @pagination.next_cursor[:anchor_column]
|
23
|
+
anchor_id: @pagination.next_cursor[:anchor_id],
|
24
|
+
anchor_value: @pagination.next_cursor[:anchor_value],
|
25
|
+
sort_direction: @pagination.next_cursor[:sort_direction]
|
27
26
|
)
|
28
27
|
```
|
29
28
|
|
@@ -35,15 +34,33 @@ json.models @pagination.resources do |resource|
|
|
35
34
|
end
|
36
35
|
|
37
36
|
json.pagination do
|
38
|
-
json.
|
37
|
+
json.next_path @next_path
|
39
38
|
end
|
40
39
|
```
|
41
40
|
|
42
41
|
## API
|
43
42
|
|
44
|
-
### `#
|
43
|
+
### `#next_cursor`
|
44
|
+
|
45
|
+
Returns the next page's cursor.
|
45
46
|
|
46
|
-
|
47
|
+
```ruby
|
48
|
+
query = Model.where(params[:filters])
|
49
|
+
|
50
|
+
@pagination = Pageturner.new(
|
51
|
+
anchor_column: "name",
|
52
|
+
anchor_id: params[:last_id],
|
53
|
+
anchor_value: params[:last_value],
|
54
|
+
ar_relation: query,
|
55
|
+
sort_direction: Pageturner::DESC,
|
56
|
+
page_size: 25
|
57
|
+
)
|
58
|
+
```
|
59
|
+
|
60
|
+
```ruby
|
61
|
+
irb(main):001:0> @pagination.next_cursor
|
62
|
+
=> {:anchor_column=>"name", :anchor_value=>"foo", :sort_direction=>"desc", :anchor_id=>3}
|
63
|
+
```
|
47
64
|
|
48
65
|
### `#resources`
|
49
66
|
|
data/lib/pageturner.rb
CHANGED
@@ -9,9 +9,8 @@ class Pageturner
|
|
9
9
|
# @param [String|Number|nil] anchor_value - Value of the anchor_column for the record to paginate from.
|
10
10
|
# @param [ActiveRecord::Relation] ar_relation - Resource collection to paginate.
|
11
11
|
# @param [String] sort_direction - Order of the pagination. Valid values: Pageturner::ASC, Pageturner::DESC.
|
12
|
-
# @param [Proc] path_helper - Function that generates the next page link. This function should have any state that's not relevant to pagination partially applied.
|
13
12
|
# @param [Number] anchor_id - ID of the record to paginate from.
|
14
|
-
def initialize(anchor_column:, anchor_value:, ar_relation:, sort_direction:, page_size:,
|
13
|
+
def initialize(anchor_column:, anchor_value:, ar_relation:, sort_direction:, page_size:, anchor_id:)
|
15
14
|
# To be used outside dynamic SQL statements.
|
16
15
|
@anchor_column = anchor_column
|
17
16
|
|
@@ -29,7 +28,6 @@ class Pageturner
|
|
29
28
|
|
30
29
|
@sort_direction = sort_direction
|
31
30
|
@page_size = page_size
|
32
|
-
@path_helper = path_helper
|
33
31
|
@anchor_id = anchor_id
|
34
32
|
|
35
33
|
unless [Pageturner::ASC, Pageturner::DESC].include?(@sort_direction)
|
@@ -44,7 +42,7 @@ class Pageturner
|
|
44
42
|
@result = calculate_resources
|
45
43
|
end
|
46
44
|
|
47
|
-
def
|
45
|
+
def next_cursor
|
48
46
|
anchor_value =
|
49
47
|
if external_anchor_column?
|
50
48
|
public_send_chain_from_sql(self.resources.last, @anchor_column)
|
@@ -52,12 +50,12 @@ class Pageturner
|
|
52
50
|
self.resources.last&.public_send(@anchor_column)
|
53
51
|
end
|
54
52
|
|
55
|
-
|
53
|
+
{
|
56
54
|
anchor_column: @anchor_column,
|
57
55
|
anchor_value: anchor_value,
|
58
56
|
sort_direction: @sort_direction,
|
59
57
|
anchor_id: self.resources.last&.id
|
60
|
-
|
58
|
+
}
|
61
59
|
end
|
62
60
|
|
63
61
|
private
|
data/pageturner.gemspec
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pageturner
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 3.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- crzrcn
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2018-01-31 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|