pageturner 4.0.0 → 4.1.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 +6 -0
- data/README.md +9 -0
- data/lib/pageturner.rb +18 -14
- 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: eaeccd8d18f2c48b0c8c4d86b07221cacb1923ec
|
4
|
+
data.tar.gz: 5041e0de3262ad5b06c442be7e904a771c9c6b20
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7ef1390fc398ba7daa3fa207c7cf9fe947d676c8e07d843a76d8a60fbfd2c50c7d295f49a5ed1ee510f8d37b6d912b751453dd31803c327737276573ac011808
|
7
|
+
data.tar.gz: ffe3748684edeae86561ced8c73e01a4d873d9282486ddcf4837d25125f2951ed7b94120d0bbc065ed07c00296a37e9974ff87a8ad9a9ef2057e4875f0f0ffbf
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,9 @@
|
|
1
|
+
# v4.0.0
|
2
|
+
|
3
|
+
## Backwards Incompatible Changes
|
4
|
+
|
5
|
+
* Support pagination over columns that are referenced differently in the database schema than in the application code. Although this looks like a feature add, it does break backwards compatibility on the assumptions that Pageturner makes on how the `anchor_column` is referenced in your database and application. Pageturner will now make less assumptions about that by allowing users to pass in database and application translations for the `anchor_column` as input. **Test your use cases after upgrading.**
|
6
|
+
|
1
7
|
# v3.1.0
|
2
8
|
|
3
9
|
## Changes
|
data/README.md
CHANGED
@@ -56,6 +56,15 @@ Pageturner will send the `anchor_column_active_record_identifier` as a method ch
|
|
56
56
|
|
57
57
|
## API
|
58
58
|
|
59
|
+
### `#has_next_page?`
|
60
|
+
|
61
|
+
Returns whether or not there is a next page.
|
62
|
+
|
63
|
+
```ruby
|
64
|
+
irb(main):001:0> @pagination.has_next_page?
|
65
|
+
=> true
|
66
|
+
```
|
67
|
+
|
59
68
|
### `#next_cursor`
|
60
69
|
|
61
70
|
Returns the next page's cursor.
|
data/lib/pageturner.rb
CHANGED
@@ -4,6 +4,7 @@ class Pageturner
|
|
4
4
|
DESC = "desc"
|
5
5
|
GREATER_THAN_OPERATOR = ">"
|
6
6
|
LESS_THAN_OPERATOR = "<"
|
7
|
+
LOOKAHEAD = 1
|
7
8
|
|
8
9
|
# @param [String] anchor_column - Field to paginate on.
|
9
10
|
# @param [Anything, nil] anchor_value - Value of the anchor_column for the record to paginate from.
|
@@ -36,6 +37,13 @@ class Pageturner
|
|
36
37
|
end
|
37
38
|
end
|
38
39
|
|
40
|
+
def has_next_page?
|
41
|
+
# Load the current page.
|
42
|
+
self.resources
|
43
|
+
|
44
|
+
@has_next_page
|
45
|
+
end
|
46
|
+
|
39
47
|
def resources
|
40
48
|
# Memoize expensive querying.
|
41
49
|
return @result if defined?(@result)
|
@@ -56,20 +64,16 @@ class Pageturner
|
|
56
64
|
private
|
57
65
|
|
58
66
|
def calculate_resources
|
59
|
-
resources
|
60
|
-
|
61
|
-
|
62
|
-
else
|
63
|
-
calculate_first_page
|
64
|
-
end
|
65
|
-
|
66
|
-
resources
|
67
|
+
(can_calculate_nth_page? ? calculate_next_page : calculate_first_page).tap do |resources|
|
68
|
+
@has_next_page = resources.size > @page_size
|
69
|
+
end.take(@page_size)
|
67
70
|
end
|
68
71
|
|
69
72
|
def comparator_for_fetching_resources
|
70
|
-
|
73
|
+
case @sort_direction
|
74
|
+
when Pageturner::ASC
|
71
75
|
GREATER_THAN_OPERATOR
|
72
|
-
|
76
|
+
when Pageturner::DESC
|
73
77
|
LESS_THAN_OPERATOR
|
74
78
|
else
|
75
79
|
raise COMPARATOR_INTERNAL_BUG
|
@@ -81,7 +85,7 @@ class Pageturner
|
|
81
85
|
end
|
82
86
|
|
83
87
|
def calculate_first_page
|
84
|
-
|
88
|
+
apply_order_and_limit(@ar_relation)
|
85
89
|
end
|
86
90
|
|
87
91
|
def calculate_next_page
|
@@ -107,13 +111,13 @@ class Pageturner
|
|
107
111
|
@ar_relation.where("#{qualified_anchor_column} IS NULL AND #{qualified_anchor_pk_column} #{comparator_for_fetching_resources} ?", @anchor_id)
|
108
112
|
end
|
109
113
|
|
110
|
-
|
114
|
+
apply_order_and_limit(where_clause)
|
111
115
|
end
|
112
116
|
|
113
|
-
def
|
117
|
+
def apply_order_and_limit(ar_relation)
|
114
118
|
ar_relation
|
115
119
|
.order("#{@anchor_column_sql_identifier} #{@sort_direction}", @ar_relation.primary_key => @sort_direction)
|
116
|
-
.limit(@page_size)
|
120
|
+
.limit(@page_size + LOOKAHEAD)
|
117
121
|
end
|
118
122
|
|
119
123
|
def nulls_listed_first?
|
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.
|
4
|
+
version: 4.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- crzrcn
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-03-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|