rb_pager 0.1.0 → 0.1.1
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/.github/workflows/ruby.yml +36 -0
- data/Gemfile +0 -3
- data/Gemfile.lock +62 -0
- data/README.md +2 -1
- data/lib/rb_pager.rb +3 -2
- data/lib/rb_pager/orm/pager_active_record.rb +5 -2
- data/lib/rb_pager/version.rb +1 -1
- data/rb_pager.gemspec +8 -4
- metadata +40 -10
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: '08d892ce787fddafc76730efd1e2712da4424f483cfb93d17ec217e70530cefc'
|
4
|
+
data.tar.gz: 1cbe5622d6f768047495fcc4a86eb87aabcab41cfc835a6e312d4c63acff9114
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: abf2b7864075d88dc03fc3e615033cb428ca773e972338013199f0bf0490dbb5d6c8e8b95917b910b522499339c240756324ffab15a1475f8b6b5d1bf9a7d79f
|
7
|
+
data.tar.gz: 2995f411fa986b57b746ffee5c5148a3fab4241cdd22e0f6b09ba60e575a1e5179244c577e2ee44289f1cc7f1defc1b76b0914e2814ad4f476145cce673af782
|
@@ -0,0 +1,36 @@
|
|
1
|
+
# This workflow uses actions that are not certified by GitHub.
|
2
|
+
# They are provided by a third-party and are governed by
|
3
|
+
# separate terms of service, privacy policy, and support
|
4
|
+
# documentation.
|
5
|
+
# This workflow will download a prebuilt Ruby version, install dependencies and run tests with Rake
|
6
|
+
# For more information see: https://github.com/marketplace/actions/setup-ruby-jruby-and-truffleruby
|
7
|
+
|
8
|
+
name: build
|
9
|
+
|
10
|
+
on:
|
11
|
+
push:
|
12
|
+
branches: [ master ]
|
13
|
+
pull_request:
|
14
|
+
branches: [ master ]
|
15
|
+
|
16
|
+
jobs:
|
17
|
+
test:
|
18
|
+
|
19
|
+
runs-on: ubuntu-latest
|
20
|
+
|
21
|
+
steps:
|
22
|
+
- uses: actions/checkout@v2
|
23
|
+
- name: Set up Ruby
|
24
|
+
# To automatically get bug fixes and new Ruby versions for ruby/setup-ruby,
|
25
|
+
# change this to (see https://github.com/ruby/setup-ruby#versioning):
|
26
|
+
# uses: ruby/setup-ruby@v1
|
27
|
+
uses: ruby/setup-ruby@ec106b438a1ff6ff109590de34ddc62c540232e0
|
28
|
+
with:
|
29
|
+
ruby-version: 2.6
|
30
|
+
- name: Setup System
|
31
|
+
run: |
|
32
|
+
sudo apt-get install libsqlite3-dev
|
33
|
+
- name: Install dependencies
|
34
|
+
run: bundle install
|
35
|
+
- name: Run tests
|
36
|
+
run: bundle exec rake
|
data/Gemfile
CHANGED
data/Gemfile.lock
ADDED
@@ -0,0 +1,62 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
rb_pager (0.1.0)
|
5
|
+
|
6
|
+
GEM
|
7
|
+
remote: https://rubygems.org/
|
8
|
+
specs:
|
9
|
+
activemodel (6.0.3.2)
|
10
|
+
activesupport (= 6.0.3.2)
|
11
|
+
activerecord (6.0.3.2)
|
12
|
+
activemodel (= 6.0.3.2)
|
13
|
+
activesupport (= 6.0.3.2)
|
14
|
+
activesupport (6.0.3.2)
|
15
|
+
concurrent-ruby (~> 1.0, >= 1.0.2)
|
16
|
+
i18n (>= 0.7, < 2)
|
17
|
+
minitest (~> 5.1)
|
18
|
+
tzinfo (~> 1.1)
|
19
|
+
zeitwerk (~> 2.2, >= 2.2.2)
|
20
|
+
coderay (1.1.3)
|
21
|
+
concurrent-ruby (1.1.6)
|
22
|
+
diff-lcs (1.4.4)
|
23
|
+
i18n (1.8.3)
|
24
|
+
concurrent-ruby (~> 1.0)
|
25
|
+
method_source (1.0.0)
|
26
|
+
minitest (5.14.1)
|
27
|
+
pry (0.13.1)
|
28
|
+
coderay (~> 1.1)
|
29
|
+
method_source (~> 1.0)
|
30
|
+
rake (13.0.1)
|
31
|
+
rspec (3.9.0)
|
32
|
+
rspec-core (~> 3.9.0)
|
33
|
+
rspec-expectations (~> 3.9.0)
|
34
|
+
rspec-mocks (~> 3.9.0)
|
35
|
+
rspec-core (3.9.2)
|
36
|
+
rspec-support (~> 3.9.3)
|
37
|
+
rspec-expectations (3.9.2)
|
38
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
39
|
+
rspec-support (~> 3.9.0)
|
40
|
+
rspec-mocks (3.9.1)
|
41
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
42
|
+
rspec-support (~> 3.9.0)
|
43
|
+
rspec-support (3.9.3)
|
44
|
+
sqlite3 (1.4.2)
|
45
|
+
thread_safe (0.3.6)
|
46
|
+
tzinfo (1.2.7)
|
47
|
+
thread_safe (~> 0.1)
|
48
|
+
zeitwerk (2.3.1)
|
49
|
+
|
50
|
+
PLATFORMS
|
51
|
+
ruby
|
52
|
+
|
53
|
+
DEPENDENCIES
|
54
|
+
activerecord (>= 5.2)
|
55
|
+
pry
|
56
|
+
rake (~> 13.0)
|
57
|
+
rb_pager!
|
58
|
+
rspec (~> 3.0)
|
59
|
+
sqlite3
|
60
|
+
|
61
|
+
BUNDLED WITH
|
62
|
+
2.1.4
|
data/README.md
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
|
2
2
|
# Pager
|
3
|
-
|
3
|
+
[](https://badge.fury.io/rb/rb_pager)
|
4
|
+

|
4
5
|
|
5
6
|
Cursor-based pagination (aka keyset pagination) is a [common](https://slack.engineering/evolving-api-pagination-at-slack-1c1f644f8e12) [pagination strategy](https://www.citusdata.com/blog/2016/03/30/five-ways-to-paginate/) that avoids many of the pitfalls of “offset–limit” pagination.
|
6
7
|
|
data/lib/rb_pager.rb
CHANGED
@@ -1,9 +1,10 @@
|
|
1
1
|
require 'active_record'
|
2
2
|
require 'rb_pager/version'
|
3
|
-
require
|
3
|
+
require 'rb_pager/configuration'
|
4
|
+
require 'pry'
|
4
5
|
|
5
6
|
module RbPager
|
6
|
-
class
|
7
|
+
class InvalidLimitValueError < StandardError; end
|
7
8
|
|
8
9
|
class << self
|
9
10
|
attr_accessor :configuration
|
@@ -6,9 +6,12 @@ module RbPager
|
|
6
6
|
AR_ORDER = { '+' => :asc, '-' => :desc }
|
7
7
|
AREL_ORDER = { asc: :gt, desc: :lt }
|
8
8
|
|
9
|
-
def pager(after
|
9
|
+
def pager(after: nil, limit: nil, sort: nil)
|
10
10
|
page_limit = limit || RbPager.configuration.limit
|
11
11
|
sort_params = sort
|
12
|
+
|
13
|
+
raise InvalidLimitValueError if limit && limit < 1
|
14
|
+
|
12
15
|
sorted_columns, sorter = build_order_expression(sort)
|
13
16
|
collection = if after.nil?
|
14
17
|
order(sorter).extending(ActiveRecordRelationMethods).limit(page_limit)
|
@@ -81,7 +84,7 @@ module RbPager
|
|
81
84
|
next_cursor = next_cursor(collection, sorted_columns)
|
82
85
|
|
83
86
|
meta = { next_cursor: next_cursor }
|
84
|
-
[collection
|
87
|
+
[collection, meta]
|
85
88
|
end
|
86
89
|
|
87
90
|
def next_cursor(collection, sorted_columns)
|
data/lib/rb_pager/version.rb
CHANGED
data/rb_pager.gemspec
CHANGED
@@ -7,8 +7,10 @@ Gem::Specification.new do |spec|
|
|
7
7
|
spec.email = ["mejbambang@gmail.com"]
|
8
8
|
|
9
9
|
spec.summary = "Cursor based pagination for active_record currently"
|
10
|
-
spec.description =
|
11
|
-
|
10
|
+
spec.description = <<~DESC
|
11
|
+
ActiveRecord plugin for cursor based pagination for Ruby on Rails.
|
12
|
+
Cursor-based pagination (aka keyset pagination) is a common pagination strategy that avoids many of the pitfalls of “offset–limit” pagination.
|
13
|
+
DESC
|
12
14
|
spec.homepage = "https://github.com/BambangSinaga/rb_pager"
|
13
15
|
spec.license = "MIT"
|
14
16
|
spec.required_ruby_version = Gem::Requirement.new(">= 2.3.0")
|
@@ -19,9 +21,11 @@ Gem::Specification.new do |spec|
|
|
19
21
|
spec.metadata["source_code_uri"] = "https://github.com/BambangSinaga/rb_pager"
|
20
22
|
# spec.metadata["changelog_uri"] = "TODO: Put your gem's CHANGELOG.md URL here."
|
21
23
|
|
24
|
+
spec.add_development_dependency "activerecord", ">= 5.2"
|
25
|
+
spec.add_development_dependency "rake", "~> 13.0"
|
26
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
22
27
|
spec.add_development_dependency "sqlite3"
|
23
|
-
spec.add_development_dependency "
|
24
|
-
spec.add_development_dependency "rspec"
|
28
|
+
spec.add_development_dependency "pry"
|
25
29
|
|
26
30
|
# Specify which files should be added to the gem when it is released.
|
27
31
|
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
metadata
CHANGED
@@ -1,31 +1,59 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rb_pager
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- BambangSinaga
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-07-
|
11
|
+
date: 2020-07-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
|
-
name:
|
14
|
+
name: activerecord
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
17
|
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '
|
19
|
+
version: '5.2'
|
20
20
|
type: :development
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '
|
26
|
+
version: '5.2'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
|
-
name:
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '13.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '13.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: sqlite3
|
29
57
|
requirement: !ruby/object:Gem::Requirement
|
30
58
|
requirements:
|
31
59
|
- - ">="
|
@@ -39,7 +67,7 @@ dependencies:
|
|
39
67
|
- !ruby/object:Gem::Version
|
40
68
|
version: '0'
|
41
69
|
- !ruby/object:Gem::Dependency
|
42
|
-
name:
|
70
|
+
name: pry
|
43
71
|
requirement: !ruby/object:Gem::Requirement
|
44
72
|
requirements:
|
45
73
|
- - ">="
|
@@ -52,19 +80,21 @@ dependencies:
|
|
52
80
|
- - ">="
|
53
81
|
- !ruby/object:Gem::Version
|
54
82
|
version: '0'
|
55
|
-
description:
|
56
|
-
ActiveRecord plugin for cursor based pagination for Ruby on Rails.
|
57
|
-
|
83
|
+
description: |
|
84
|
+
ActiveRecord plugin for cursor based pagination for Ruby on Rails.
|
85
|
+
Cursor-based pagination (aka keyset pagination) is a common pagination strategy that avoids many of the pitfalls of “offset–limit” pagination.
|
58
86
|
email:
|
59
87
|
- mejbambang@gmail.com
|
60
88
|
executables: []
|
61
89
|
extensions: []
|
62
90
|
extra_rdoc_files: []
|
63
91
|
files:
|
92
|
+
- ".github/workflows/ruby.yml"
|
64
93
|
- ".gitignore"
|
65
94
|
- ".rspec"
|
66
95
|
- ".travis.yml"
|
67
96
|
- Gemfile
|
97
|
+
- Gemfile.lock
|
68
98
|
- LICENSE.txt
|
69
99
|
- README.md
|
70
100
|
- Rakefile
|