pagy_cursor 0.2.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 59535b7b4048ff1ca8d86d899e95846e3c67ffc2023d64742480a558d1d6d242
4
- data.tar.gz: c5138ff0b4a0f6b11b0f0ed49973bc057d387009e961571c45f5b0bb0d5f08f3
3
+ metadata.gz: db5bbbc8ad4eeacb38c8f09bf5ce0e7b740741f128e955a04edad241ca164b47
4
+ data.tar.gz: 89c124e2905ab7f3a9e60ed6afc74576066faa55fcc028f42142bf07056400ee
5
5
  SHA512:
6
- metadata.gz: 90a0760bb69481f533719430fcf3b12c042b7b6956880135e5b4e03974f73f8451d303b44717c55d8f46378d30e0b993cb19416095752844da261cda8f49c934
7
- data.tar.gz: e8a2040f3308dcf405ece7720c467241e8009b6a7b1d3f0c10dede7f9aec8f55a97f2d7cb396d3d2ddaef2b612811c191739e95cff6c17ebcd615e6f9e84afe6
6
+ metadata.gz: 023b19a137c638a766107721ec7e728d0ebfa6b32788686a9edaeecc469d04b609519bf0bc8c72d807f396338fdb294f185d8c538f62386e1c00e8f702eb4232
7
+ data.tar.gz: 7d8731348178705c581d886f8b3f409e5e661cd90a93dd6e1fb79aede4ecbc1c625e5142d7ec65c624a8d7e0fc673907ca98fabb7ba313d8e58af9c01dc16e73
@@ -0,0 +1,104 @@
1
+ name: Pagy Cursor CI
2
+
3
+ on:
4
+ push:
5
+ branches: ['**']
6
+ pull_request:
7
+ branches: ['**']
8
+
9
+ jobs:
10
+ postgres_test:
11
+ name: Ruby ${{ matrix.ruby-version }} Test with postgresql
12
+
13
+ runs-on: ubuntu-latest
14
+
15
+ services:
16
+ postgres:
17
+ image: postgres
18
+ env:
19
+ POSTGRES_USER: postgres
20
+ POSTGRES_PASSWORD: postgres
21
+ options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5
22
+ ports:
23
+ - 5432:5432
24
+
25
+ strategy:
26
+ matrix:
27
+ include:
28
+ - ruby-version: 2.5
29
+ env:
30
+ BUNDLE_GEMFILE: gemfiles/active_record_50.gemfile
31
+ - ruby-version: 2.6
32
+ env:
33
+ BUNDLE_GEMFILE: gemfiles/active_record_51.gemfile
34
+ - ruby-version: 2.7
35
+ env:
36
+ BUNDLE_GEMFILE: gemfiles/active_record_52.gemfile
37
+ - ruby-version: 3.0
38
+ env:
39
+ BUNDLE_GEMFILE: gemfiles/active_record_60.gemfile
40
+
41
+ fail-fast: false
42
+ env: ${{ matrix.env }}
43
+
44
+ steps:
45
+ - uses: actions/checkout@v2
46
+
47
+ - name: Set up ruby
48
+ uses: ruby/setup-ruby@v1
49
+ with:
50
+ ruby-version: ${{ matrix.ruby-version }}
51
+ bundler-cache: true # runs 'bundle install' and caches installed gems automatically
52
+
53
+ - name: Run Ruby Tests
54
+ run: bundle exec rspec
55
+ env:
56
+ DB: postgresql
57
+ DB_PASSWORD: postgres
58
+
59
+ mysql_test:
60
+ name: Ruby ${{ matrix.ruby-version }} Test with mysql
61
+
62
+ runs-on: ubuntu-latest
63
+
64
+ services:
65
+ mysql:
66
+ image: mysql
67
+ env:
68
+ MYSQL_PASSWORD: rootpassword
69
+ MYSQL_ROOT_PASSWORD: rootpassword
70
+ ports:
71
+ - 3306:3306
72
+ options: --health-cmd "mysqladmin ping" --health-interval 10s --health-timeout 5s --health-retries 10
73
+
74
+ strategy:
75
+ matrix:
76
+ include:
77
+ - ruby-version: 2.5
78
+ env:
79
+ BUNDLE_GEMFILE: gemfiles/active_record_50.gemfile
80
+ - ruby-version: 2.6
81
+ env:
82
+ BUNDLE_GEMFILE: gemfiles/active_record_51.gemfile
83
+ - ruby-version: 2.7
84
+ env:
85
+ BUNDLE_GEMFILE: gemfiles/active_record_52.gemfile
86
+ - ruby-version: 3.0
87
+ env:
88
+ BUNDLE_GEMFILE: gemfiles/active_record_60.gemfile
89
+ fail-fast: false
90
+ env: ${{ matrix.env }}
91
+ steps:
92
+ - uses: actions/checkout@v2
93
+
94
+ - name: Set up ruby
95
+ uses: ruby/setup-ruby@v1
96
+ with:
97
+ ruby-version: ${{ matrix.ruby-version }}
98
+ bundler-cache: true # runs 'bundle install' and caches installed gems automatically
99
+
100
+ - name: Run Ruby Tests
101
+ run: bundle exec rspec
102
+ env:
103
+ DB: mysql
104
+ DB_PASSWORD: rootpassword
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- pagy_cursor (0.1.1)
4
+ pagy_cursor (0.2.0)
5
5
  activerecord (>= 5)
6
6
  pagy
7
7
 
@@ -83,18 +83,20 @@ GEM
83
83
  method_source (0.9.2)
84
84
  mimemagic (0.3.4)
85
85
  mini_mime (1.0.2)
86
- mini_portile2 (2.4.0)
86
+ mini_portile2 (2.6.1)
87
87
  minitest (5.14.0)
88
88
  mysql2 (0.5.3)
89
89
  nio4r (2.5.2)
90
- nokogiri (1.10.9)
91
- mini_portile2 (~> 2.4.0)
92
- pagy (3.7.3)
90
+ nokogiri (1.12.5)
91
+ mini_portile2 (~> 2.6.1)
92
+ racc (~> 1.4)
93
+ pagy (3.8.2)
93
94
  pg (1.2.2)
94
95
  pry (0.12.2)
95
96
  coderay (~> 1.1.0)
96
97
  method_source (~> 0.9.0)
97
- rack (2.2.2)
98
+ racc (1.5.2)
99
+ rack (2.2.3)
98
100
  rack-test (1.1.0)
99
101
  rack (>= 1.0, < 3)
100
102
  rails (6.0.2.1)
@@ -151,7 +153,7 @@ GEM
151
153
  thread_safe (~> 0.1)
152
154
  websocket-driver (0.7.1)
153
155
  websocket-extensions (>= 0.1.0)
154
- websocket-extensions (0.1.4)
156
+ websocket-extensions (0.1.5)
155
157
  zeitwerk (2.3.0)
156
158
 
157
159
  PLATFORMS
data/README.md CHANGED
@@ -1,6 +1,5 @@
1
1
 
2
2
  # PagyCursor
3
- ![](https://travis-ci.org/Uysim/pagy-cursor.svg?branch=master)
4
3
 
5
4
  Extra [Pagy](https://github.com/ddnexus/pagy) to work with cursor pagination
6
5
 
@@ -23,7 +22,7 @@ Include the backend in some controller:
23
22
 
24
23
  ```ruby
25
24
  require "pagy_cursor/pagy/extras/cursor"
26
- require "pagy_cursor/pagy/extras/cursor_uuid"
25
+ require "pagy_cursor/pagy/extras/uuid_cursor"
27
26
 
28
27
  include Pagy::Backend
29
28
  ```
@@ -73,8 +72,8 @@ To run tests in root folder of gem:
73
72
  - ```bundle install```
74
73
  - ```bundle exec rspec ```
75
74
 
76
- To test on specific Rails verison
77
- ```export BUNDLE_GEMFILE=gemfiles/active_record_5.2.gemfile``` to work with Rails 5.2
75
+ To test on specific Rails version
76
+ ```export BUNDLE_GEMFILE=gemfiles/active_record_52.gemfile``` to work with Rails 5.2
78
77
 
79
78
  To play with app cd test/dummy and rails s -b 0.0.0.0 (before rails db:migrate).
80
79
 
@@ -10,7 +10,7 @@ class Pagy
10
10
  items = pagy_cursor_get_items(collection, pagy, pagy.position)
11
11
  pagy.has_more = pagy_cursor_has_more?(items, pagy)
12
12
 
13
- return pagy, items
13
+ return pagy, items[0..pagy.items-1]
14
14
  end
15
15
 
16
16
  def pagy_cursor_get_vars(collection, vars)
@@ -23,17 +23,16 @@ class Pagy
23
23
  def pagy_cursor_get_items(collection, pagy, position=nil)
24
24
  if position.present?
25
25
  sql_comparation = pagy.arel_table[pagy.primary_key].send(pagy.comparation, position)
26
- collection.where(sql_comparation).reorder(pagy.order).limit(pagy.items)
26
+ collection.where(sql_comparation).reorder(pagy.order).limit(pagy.items + 1)
27
27
  else
28
- collection.reorder(pagy.order).limit(pagy.items)
28
+ collection.reorder(pagy.order).limit(pagy.items + 1)
29
29
  end
30
30
  end
31
31
 
32
32
  def pagy_cursor_has_more?(collection, pagy)
33
33
  return false if collection.empty?
34
34
 
35
- next_position = collection.last[pagy.primary_key]
36
- pagy_cursor_get_items(collection, pagy, next_position).exists?
35
+ collection.size > pagy.items
37
36
  end
38
37
  end
39
38
  end
@@ -9,7 +9,7 @@ class Pagy
9
9
  items = pagy_uuid_cursor_get_items(collection, pagy, pagy.position)
10
10
  pagy.has_more = pagy_uuid_cursor_has_more?(items, pagy)
11
11
 
12
- return pagy, items
12
+ return pagy, items[0..pagy.items-1]
13
13
  end
14
14
 
15
15
  def pagy_uuid_cursor_get_vars(collection, vars)
@@ -29,14 +29,13 @@ class Pagy
29
29
 
30
30
  collection = collection.where(sql_comparation)
31
31
  end
32
- collection.reorder(pagy.order).limit(pagy.items)
32
+ collection.reorder(pagy.order).limit(pagy.items + 1)
33
33
  end
34
34
 
35
35
  def pagy_uuid_cursor_has_more?(collection, pagy)
36
36
  return false if collection.empty?
37
37
 
38
- next_position = collection.last[pagy.primary_key]
39
- pagy_uuid_cursor_get_items(collection, pagy, next_position).exists?
38
+ collection.size > pagy.items
40
39
  end
41
40
  end
42
41
  end
@@ -1,3 +1,3 @@
1
1
  module PagyCursor
2
- VERSION = "0.2.0"
2
+ VERSION = "0.2.1"
3
3
  end
data/pagy_cursor.gemspec CHANGED
@@ -22,7 +22,7 @@ Gem::Specification.new do |spec|
22
22
  spec.bindir = "exe"
23
23
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
24
24
  spec.require_paths = ["lib"]
25
- spec.add_dependency "pagy"
25
+ spec.add_dependency "pagy", "< 5"
26
26
  spec.add_dependency "activerecord", ">= 5"
27
27
 
28
28
  spec.add_development_dependency "bundler", "~> 2.0"
metadata CHANGED
@@ -1,29 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pagy_cursor
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Uysim
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-05-20 00:00:00.000000000 Z
11
+ date: 2021-11-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: pagy
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ">="
17
+ - - "<"
18
18
  - !ruby/object:Gem::Version
19
- version: '0'
19
+ version: '5'
20
20
  type: :runtime
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: '0'
26
+ version: '5'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: activerecord
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -87,6 +87,7 @@ executables: []
87
87
  extensions: []
88
88
  extra_rdoc_files: []
89
89
  files:
90
+ - ".github/workflows/ci.yml"
90
91
  - ".github/workflows/gempush.yml"
91
92
  - ".gitignore"
92
93
  - ".rspec"
@@ -127,7 +128,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
127
128
  - !ruby/object:Gem::Version
128
129
  version: '0'
129
130
  requirements: []
130
- rubygems_version: 3.0.3
131
+ rubygems_version: 3.2.22
131
132
  signing_key:
132
133
  specification_version: 4
133
134
  summary: cursor paginations for pagy