pageturner 1.0.0 → 2.0.0
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 +4 -4
- data/.circleci/config.yml +42 -0
- data/CHANGELOG.md +9 -0
- data/README.md +5 -7
- data/lib/pageturner.rb +3 -3
- data/pageturner.gemspec +3 -3
- metadata +6 -5
- data/.travis.yml +0 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a0afa7cf02e4c3655d869a7f421707e670a49bb3
|
4
|
+
data.tar.gz: ae0872c1dec41ce653006251e6f6a4ebedcda089
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4d40b38322ef458601ecf123096d076acfd7bb4387edd523afdbde9e2e72d3b527063d7aead28888150d52be0b610e0a06e33c5deaa3367c753a4aec53393d5b
|
7
|
+
data.tar.gz: a8f56d7eec03a48da0506cad1218a4c8f99f3ab645d25ebcc35c6a4aa4a292d09dd6684bd8955582b16b235a37b56fa53f85383355954ef4805aa93c4f3d658d
|
@@ -0,0 +1,42 @@
|
|
1
|
+
# Ruby CircleCI 2.0 configuration file
|
2
|
+
#
|
3
|
+
# Check https://circleci.com/docs/2.0/language-ruby/ for more details
|
4
|
+
#
|
5
|
+
version: 2
|
6
|
+
jobs:
|
7
|
+
build:
|
8
|
+
docker:
|
9
|
+
# specify the version you desire here
|
10
|
+
- image: circleci/ruby:2.4.1-node-browsers
|
11
|
+
|
12
|
+
# Specify service dependencies here if necessary
|
13
|
+
# CircleCI maintains a library of pre-built images
|
14
|
+
# documented at https://circleci.com/docs/2.0/circleci-images/
|
15
|
+
- image: circleci/mysql:5.7
|
16
|
+
environment:
|
17
|
+
MYSQL_DATABASE: "pageturner_test"
|
18
|
+
|
19
|
+
working_directory: ~/repo
|
20
|
+
|
21
|
+
steps:
|
22
|
+
- checkout
|
23
|
+
|
24
|
+
- run: gem install bundler
|
25
|
+
- run: bundle install --jobs=4 --retry=3 --path vendor/bundle
|
26
|
+
|
27
|
+
- save_cache:
|
28
|
+
paths:
|
29
|
+
- ./vendor/bundle
|
30
|
+
key: v1-dependencies-{{ checksum "Gemfile.lock" }}
|
31
|
+
|
32
|
+
# run tests!
|
33
|
+
- run:
|
34
|
+
name: run tests
|
35
|
+
command: bundle exec rspec --format documentation
|
36
|
+
|
37
|
+
# collect reports
|
38
|
+
- store_test_results:
|
39
|
+
path: /tmp/test-results
|
40
|
+
- store_artifacts:
|
41
|
+
path: /tmp/test-results
|
42
|
+
destination: test-results
|
data/CHANGELOG.md
ADDED
@@ -0,0 +1,9 @@
|
|
1
|
+
# v2.0.0
|
2
|
+
|
3
|
+
## Backwards Incompatible Changes
|
4
|
+
|
5
|
+
* https://github.com/crzrcn/pageturner/pull/6 - Do not make any assumptions over page size. The page size for a collection is ultimetaly known by the caller, so we accept a `page_size` parameter and use that value for the limit clause we apply on the given ActiveRecord::Relation. Before this change, Pageturner would apply a hardcoded page size that was defined within Pageturner itself. Users will need to modify their programs to pass the page size since Pageturner no longer enforces a page size.
|
6
|
+
|
7
|
+
# v1.0.0
|
8
|
+
|
9
|
+
* Support Rails 4.2 and 5.1.
|
data/README.md
CHANGED
@@ -1,23 +1,21 @@
|
|
1
1
|
# Pageturner
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
TODO: remove page size. let the caller limit the relation accordingly
|
6
|
-
TODO: remove the path helper. expose the cursor instead and let the caller generate the next link
|
7
|
-
TODO: automate testing setup that requires installing mysql, starting the server, creating the database, etc.
|
8
|
-
TODO: make gem database agnostic
|
3
|
+
Cursor based pagination for activerecord queries.
|
9
4
|
|
10
5
|
## Usage
|
11
6
|
|
12
7
|
In your controllers:
|
13
8
|
|
14
9
|
```ruby
|
10
|
+
query = Model.where(params[:filters])
|
11
|
+
|
15
12
|
@pagination = Pageturner.new(
|
16
13
|
anchor_column: "name",
|
17
14
|
anchor_id: params[:last_id],
|
18
15
|
anchor_value: params[:last_value],
|
19
|
-
ar_relation:
|
16
|
+
ar_relation: query,
|
20
17
|
sort_direction: Pageturner::DESC,
|
18
|
+
page_size: 25,
|
21
19
|
path_helper: lambda do |anchor_column:, anchor_value:, sort_direction:, anchor_id:|
|
22
20
|
models_path(
|
23
21
|
anchor_column: anchor_column,
|
data/lib/pageturner.rb
CHANGED
@@ -4,7 +4,6 @@ class Pageturner
|
|
4
4
|
DESC = "desc"
|
5
5
|
GREATER_THAN_OPERATOR = ">"
|
6
6
|
LESS_THAN_OPERATOR = "<"
|
7
|
-
PAGE_SIZE = 3 # TODO: remove since it's a caller concern.
|
8
7
|
|
9
8
|
# @param [String] anchor_column - Field to paginate on.
|
10
9
|
# @param [String|Number|nil] anchor_value - Value of the anchor_column for the record to paginate from.
|
@@ -12,7 +11,7 @@ class Pageturner
|
|
12
11
|
# @param [String] sort_direction - Order of the pagination. Valid values: Pageturner::ASC, Pageturner::DESC.
|
13
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.
|
14
13
|
# @param [Number] anchor_id - ID of the record to paginate from.
|
15
|
-
def initialize(anchor_column:, anchor_value:, ar_relation:, sort_direction:, path_helper:, anchor_id:)
|
14
|
+
def initialize(anchor_column:, anchor_value:, ar_relation:, sort_direction:, page_size:, path_helper:, anchor_id:)
|
16
15
|
# To be used outside dynamic SQL statements.
|
17
16
|
@anchor_column = anchor_column
|
18
17
|
|
@@ -29,6 +28,7 @@ class Pageturner
|
|
29
28
|
end
|
30
29
|
|
31
30
|
@sort_direction = sort_direction
|
31
|
+
@page_size = page_size
|
32
32
|
@path_helper = path_helper
|
33
33
|
@anchor_id = anchor_id
|
34
34
|
|
@@ -119,7 +119,7 @@ class Pageturner
|
|
119
119
|
def apply_sort_direction(ar_relation)
|
120
120
|
ar_relation
|
121
121
|
.order("#{@anchor_column} #{@sort_direction}", @ar_relation.primary_key => @sort_direction)
|
122
|
-
.limit(
|
122
|
+
.limit(@page_size)
|
123
123
|
end
|
124
124
|
|
125
125
|
def nulls_listed_first?
|
data/pageturner.gemspec
CHANGED
@@ -4,12 +4,12 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
4
|
|
5
5
|
Gem::Specification.new do |spec|
|
6
6
|
spec.name = "pageturner"
|
7
|
-
spec.version = "
|
7
|
+
spec.version = "2.0.0"
|
8
8
|
spec.authors = ["crzrcn"]
|
9
9
|
spec.email = ["fernanlink@gmail.com"]
|
10
10
|
|
11
|
-
spec.summary =
|
12
|
-
spec.description =
|
11
|
+
spec.summary = "Cursor based pagination for activerecord queries."
|
12
|
+
spec.description = "Cursor based pagination for activerecord queries."
|
13
13
|
spec.homepage = "https://github.com/crzrcn/pageturner"
|
14
14
|
|
15
15
|
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
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: 2.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: 2017-12-
|
11
|
+
date: 2017-12-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
@@ -100,16 +100,17 @@ dependencies:
|
|
100
100
|
- - "~>"
|
101
101
|
- !ruby/object:Gem::Version
|
102
102
|
version: '3.5'
|
103
|
-
description:
|
103
|
+
description: Cursor based pagination for activerecord queries.
|
104
104
|
email:
|
105
105
|
- fernanlink@gmail.com
|
106
106
|
executables: []
|
107
107
|
extensions: []
|
108
108
|
extra_rdoc_files: []
|
109
109
|
files:
|
110
|
+
- ".circleci/config.yml"
|
110
111
|
- ".gitignore"
|
111
112
|
- ".rspec"
|
112
|
-
-
|
113
|
+
- CHANGELOG.md
|
113
114
|
- Gemfile
|
114
115
|
- README.md
|
115
116
|
- Rakefile
|
@@ -140,5 +141,5 @@ rubyforge_project:
|
|
140
141
|
rubygems_version: 2.5.2
|
141
142
|
signing_key:
|
142
143
|
specification_version: 4
|
143
|
-
summary:
|
144
|
+
summary: Cursor based pagination for activerecord queries.
|
144
145
|
test_files: []
|