pagy_cursor 0.1.1 → 0.2.0

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: ab31fcaa027ea7c3a4a39a695505a6215672457b29775bf8139e8ae69de7faff
4
- data.tar.gz: b49aeed576699eb3e1237c25ee69e569f0ae0a55e857462dc7473d79e0755d80
3
+ metadata.gz: 59535b7b4048ff1ca8d86d899e95846e3c67ffc2023d64742480a558d1d6d242
4
+ data.tar.gz: c5138ff0b4a0f6b11b0f0ed49973bc057d387009e961571c45f5b0bb0d5f08f3
5
5
  SHA512:
6
- metadata.gz: 687d9a0b4acc0570f333f19f868ff4c19a3866c4515efdd32e0e04086e62b9c928a9be3a472efa39bbe988344deb28a0fde50c3ea85704fa3ff1575e0de34bd1
7
- data.tar.gz: 23c476eed3f2963fa2080a1b11019a17f23ee563499441fb45eed0837d84e8e26aaeb297a3253c0bc8e3ad3006cf3f0d2c45678a5983c0ec068cb92af93a19b1
6
+ metadata.gz: 90a0760bb69481f533719430fcf3b12c042b7b6956880135e5b4e03974f73f8451d303b44717c55d8f46378d30e0b993cb19416095752844da261cda8f49c934
7
+ data.tar.gz: e8a2040f3308dcf405ece7720c467241e8009b6a7b1d3f0c10dede7f9aec8f55a97f2d7cb396d3d2ddaef2b612811c191739e95cff6c17ebcd615e6f9e84afe6
@@ -0,0 +1,28 @@
1
+ name: Ruby Gem
2
+
3
+ on:
4
+ push:
5
+ tags:
6
+ - '*'
7
+ jobs:
8
+ build:
9
+ name: Build + Publish
10
+ runs-on: ubuntu-latest
11
+
12
+ steps:
13
+ - uses: actions/checkout@v2
14
+ - name: Set up Ruby 2.6
15
+ uses: actions/setup-ruby@v1
16
+ with:
17
+ version: 2.6.x
18
+
19
+ - name: Publish to RubyGems
20
+ run: |
21
+ mkdir -p $HOME/.gem
22
+ touch $HOME/.gem/credentials
23
+ chmod 0600 $HOME/.gem/credentials
24
+ printf -- "---\n:rubygems_api_key: ${GEM_HOST_API_KEY}\n" > $HOME/.gem/credentials
25
+ gem build *.gemspec
26
+ gem push *.gem
27
+ env:
28
+ GEM_HOST_API_KEY: ${{secrets.RUBYGEMS_API_KEY}}
data/.gitignore CHANGED
@@ -13,3 +13,5 @@
13
13
  gemfiles/*.lock
14
14
  log
15
15
  *.sqlite3
16
+
17
+ spec/dummy/tmp
data/Gemfile ADDED
@@ -0,0 +1,11 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ gem "rails", "~> 6.0.0"
6
+ gem "pg"
7
+ gem "sqlite3"
8
+ gem "mysql2"
9
+ gem "pry"
10
+ # Specify your gem's dependencies in pagy_cursor.gemspec
11
+ gemspec path: "./"
@@ -0,0 +1,172 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ pagy_cursor (0.1.1)
5
+ activerecord (>= 5)
6
+ pagy
7
+
8
+ GEM
9
+ remote: https://rubygems.org/
10
+ specs:
11
+ actioncable (6.0.2.1)
12
+ actionpack (= 6.0.2.1)
13
+ nio4r (~> 2.0)
14
+ websocket-driver (>= 0.6.1)
15
+ actionmailbox (6.0.2.1)
16
+ actionpack (= 6.0.2.1)
17
+ activejob (= 6.0.2.1)
18
+ activerecord (= 6.0.2.1)
19
+ activestorage (= 6.0.2.1)
20
+ activesupport (= 6.0.2.1)
21
+ mail (>= 2.7.1)
22
+ actionmailer (6.0.2.1)
23
+ actionpack (= 6.0.2.1)
24
+ actionview (= 6.0.2.1)
25
+ activejob (= 6.0.2.1)
26
+ mail (~> 2.5, >= 2.5.4)
27
+ rails-dom-testing (~> 2.0)
28
+ actionpack (6.0.2.1)
29
+ actionview (= 6.0.2.1)
30
+ activesupport (= 6.0.2.1)
31
+ rack (~> 2.0, >= 2.0.8)
32
+ rack-test (>= 0.6.3)
33
+ rails-dom-testing (~> 2.0)
34
+ rails-html-sanitizer (~> 1.0, >= 1.2.0)
35
+ actiontext (6.0.2.1)
36
+ actionpack (= 6.0.2.1)
37
+ activerecord (= 6.0.2.1)
38
+ activestorage (= 6.0.2.1)
39
+ activesupport (= 6.0.2.1)
40
+ nokogiri (>= 1.8.5)
41
+ actionview (6.0.2.1)
42
+ activesupport (= 6.0.2.1)
43
+ builder (~> 3.1)
44
+ erubi (~> 1.4)
45
+ rails-dom-testing (~> 2.0)
46
+ rails-html-sanitizer (~> 1.1, >= 1.2.0)
47
+ activejob (6.0.2.1)
48
+ activesupport (= 6.0.2.1)
49
+ globalid (>= 0.3.6)
50
+ activemodel (6.0.2.1)
51
+ activesupport (= 6.0.2.1)
52
+ activerecord (6.0.2.1)
53
+ activemodel (= 6.0.2.1)
54
+ activesupport (= 6.0.2.1)
55
+ activestorage (6.0.2.1)
56
+ actionpack (= 6.0.2.1)
57
+ activejob (= 6.0.2.1)
58
+ activerecord (= 6.0.2.1)
59
+ marcel (~> 0.3.1)
60
+ activesupport (6.0.2.1)
61
+ concurrent-ruby (~> 1.0, >= 1.0.2)
62
+ i18n (>= 0.7, < 2)
63
+ minitest (~> 5.1)
64
+ tzinfo (~> 1.1)
65
+ zeitwerk (~> 2.2)
66
+ builder (3.2.4)
67
+ coderay (1.1.2)
68
+ concurrent-ruby (1.1.6)
69
+ crass (1.0.6)
70
+ diff-lcs (1.3)
71
+ erubi (1.9.0)
72
+ globalid (0.4.2)
73
+ activesupport (>= 4.2.0)
74
+ i18n (1.8.2)
75
+ concurrent-ruby (~> 1.0)
76
+ loofah (2.4.0)
77
+ crass (~> 1.0.2)
78
+ nokogiri (>= 1.5.9)
79
+ mail (2.7.1)
80
+ mini_mime (>= 0.1.1)
81
+ marcel (0.3.3)
82
+ mimemagic (~> 0.3.2)
83
+ method_source (0.9.2)
84
+ mimemagic (0.3.4)
85
+ mini_mime (1.0.2)
86
+ mini_portile2 (2.4.0)
87
+ minitest (5.14.0)
88
+ mysql2 (0.5.3)
89
+ nio4r (2.5.2)
90
+ nokogiri (1.10.9)
91
+ mini_portile2 (~> 2.4.0)
92
+ pagy (3.7.3)
93
+ pg (1.2.2)
94
+ pry (0.12.2)
95
+ coderay (~> 1.1.0)
96
+ method_source (~> 0.9.0)
97
+ rack (2.2.2)
98
+ rack-test (1.1.0)
99
+ rack (>= 1.0, < 3)
100
+ rails (6.0.2.1)
101
+ actioncable (= 6.0.2.1)
102
+ actionmailbox (= 6.0.2.1)
103
+ actionmailer (= 6.0.2.1)
104
+ actionpack (= 6.0.2.1)
105
+ actiontext (= 6.0.2.1)
106
+ actionview (= 6.0.2.1)
107
+ activejob (= 6.0.2.1)
108
+ activemodel (= 6.0.2.1)
109
+ activerecord (= 6.0.2.1)
110
+ activestorage (= 6.0.2.1)
111
+ activesupport (= 6.0.2.1)
112
+ bundler (>= 1.3.0)
113
+ railties (= 6.0.2.1)
114
+ sprockets-rails (>= 2.0.0)
115
+ rails-dom-testing (2.0.3)
116
+ activesupport (>= 4.2.0)
117
+ nokogiri (>= 1.6)
118
+ rails-html-sanitizer (1.3.0)
119
+ loofah (~> 2.3)
120
+ railties (6.0.2.1)
121
+ actionpack (= 6.0.2.1)
122
+ activesupport (= 6.0.2.1)
123
+ method_source
124
+ rake (>= 0.8.7)
125
+ thor (>= 0.20.3, < 2.0)
126
+ rake (13.0.1)
127
+ rspec (3.9.0)
128
+ rspec-core (~> 3.9.0)
129
+ rspec-expectations (~> 3.9.0)
130
+ rspec-mocks (~> 3.9.0)
131
+ rspec-core (3.9.1)
132
+ rspec-support (~> 3.9.1)
133
+ rspec-expectations (3.9.0)
134
+ diff-lcs (>= 1.2.0, < 2.0)
135
+ rspec-support (~> 3.9.0)
136
+ rspec-mocks (3.9.1)
137
+ diff-lcs (>= 1.2.0, < 2.0)
138
+ rspec-support (~> 3.9.0)
139
+ rspec-support (3.9.2)
140
+ sprockets (4.0.0)
141
+ concurrent-ruby (~> 1.0)
142
+ rack (> 1, < 3)
143
+ sprockets-rails (3.2.1)
144
+ actionpack (>= 4.0)
145
+ activesupport (>= 4.0)
146
+ sprockets (>= 3.0.0)
147
+ sqlite3 (1.4.2)
148
+ thor (1.0.1)
149
+ thread_safe (0.3.6)
150
+ tzinfo (1.2.6)
151
+ thread_safe (~> 0.1)
152
+ websocket-driver (0.7.1)
153
+ websocket-extensions (>= 0.1.0)
154
+ websocket-extensions (0.1.4)
155
+ zeitwerk (2.3.0)
156
+
157
+ PLATFORMS
158
+ ruby
159
+
160
+ DEPENDENCIES
161
+ bundler (~> 2.0)
162
+ mysql2
163
+ pagy_cursor!
164
+ pg
165
+ pry
166
+ rails (~> 6.0.0)
167
+ rake (~> 13.0)
168
+ rspec (~> 3.0)
169
+ sqlite3
170
+
171
+ BUNDLED WITH
172
+ 2.1.4
data/README.md CHANGED
@@ -15,31 +15,70 @@ gem 'pagy_cursor'
15
15
 
16
16
  And then execute:
17
17
 
18
- $ bundle
18
+ $ bundle install
19
19
 
20
20
  ## Usage
21
21
 
22
22
  Include the backend in some controller:
23
+
23
24
  ```ruby
24
- require "pagy_cursor"
25
+ require "pagy_cursor/pagy/extras/cursor"
26
+ require "pagy_cursor/pagy/extras/cursor_uuid"
25
27
 
26
28
  include Pagy::Backend
27
29
  ```
28
30
  Default
31
+
29
32
  ```ruby
30
33
  pagy_cursor(Post.all)
31
34
  ```
35
+
32
36
  Before and After
37
+
33
38
  ```ruby
34
39
  pagy_cursor(Post.all, after: 10)
35
40
  pagy_cursor(Post.all, before: 10)
36
41
  ```
42
+
37
43
  With UUID
44
+
38
45
  ```ruby
39
46
  pagy_uuid_cursor(Post.all, after: "ce5d2741-4e52-49b2-bb76-c41b67ab3aad")
40
47
  pagy_uuid_cursor(Post.all, before: "ce5d2741-4e52-49b2-bb76-c41b67ab3aad")
41
48
  ```
42
49
 
50
+ Ordering collection
51
+ ```ruby
52
+ pagy_cursor(Post.all, after: 10, order: {updated_at: :desc})
53
+ ```
54
+
55
+ ## Credits
56
+
57
+ Many thanks to:
58
+ - [Uysim](https://github.com/Uysim)
59
+ - [M. Yunan Helmy](https://github.com/yunanhelmy)
60
+ - [Eumir Gaspar](https://github.com/corroded)
61
+
62
+ ## Support Databases
63
+
64
+ - SQLite
65
+ - Postgresql
66
+ - MySQL
67
+
68
+ ## Tests & Contributing
69
+
70
+ To run tests in root folder of gem:
71
+
72
+ - ```export DB=sqlite3``` to work with sqlite (see [support databases](#support-databases))
73
+ - ```bundle install```
74
+ - ```bundle exec rspec ```
75
+
76
+ To test on specific Rails verison
77
+ ```export BUNDLE_GEMFILE=gemfiles/active_record_5.2.gemfile``` to work with Rails 5.2
78
+
79
+ To play with app cd test/dummy and rails s -b 0.0.0.0 (before rails db:migrate).
80
+
81
+
43
82
  ## License
44
83
 
45
84
  The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
@@ -0,0 +1,11 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ gem "rails", "~> 6.0.0"
6
+ gem "pg"
7
+ gem "sqlite3"
8
+ gem "mysql2"
9
+ gem "pry"
10
+ # Specify your gem's dependencies in pagy_cursor.gemspec
11
+ gemspec path: "../"
@@ -12,6 +12,8 @@ class Pagy
12
12
  @after = vars[:after]
13
13
  @arel_table = vars[:arel_table]
14
14
  @primary_key = vars[:primary_key]
15
+ @reorder = vars[:order] || {}
16
+
15
17
  if @before.present? and @after.present?
16
18
  raise(ArgumentError, 'before and after can not be both mentioned')
17
19
  end
@@ -20,23 +22,23 @@ class Pagy
20
22
 
21
23
  @comparation = 'lt' # arel table less than
22
24
  @position = @before
23
- @order = { :created_at => :desc , @primary_key => :desc }
25
+ @order = @reorder.merge({ :created_at => :desc , @primary_key => :desc })
24
26
 
25
- if @after.present?
27
+ if @after.present? || (@reorder.present? && @reorder.values.uniq.first.to_sym == :asc)
26
28
  @comparation = 'gt' # arel table greater than
27
29
  @position = @after
28
- @order = { :created_at => :asc , @primary_key => :asc }
30
+ @order = @reorder.merge({ :created_at => :asc , @primary_key => :asc })
29
31
  end
30
32
  else
31
33
 
32
34
  @comparation = 'lt'
33
35
  @position = @before
34
- @order = { @primary_key => :desc }
36
+ @order = @reorder.merge({ @primary_key => :desc })
35
37
 
36
- if @after.present?
38
+ if @after.present? || (@reorder.present? && @reorder.values.uniq.first.to_sym == :asc)
37
39
  @comparation = 'gt'
38
40
  @position = @after
39
- @order = { @primary_key => :asc }
41
+ @order = @reorder.merge({ @primary_key => :asc })
40
42
  end
41
43
  end
42
44
  end
@@ -1,3 +1,3 @@
1
1
  module PagyCursor
2
- VERSION = "0.1.1"
2
+ VERSION = "0.2.0"
3
3
  end
@@ -14,19 +14,6 @@ Gem::Specification.new do |spec|
14
14
  spec.homepage = "https://github.com/Uysim/pagy-cursor"
15
15
  spec.license = "MIT"
16
16
 
17
- # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
18
- # to allow pushing to a single host or delete this section to allow pushing to any host.
19
- # if spec.respond_to?(:metadata)
20
- # spec.metadata["allowed_push_host"] = "TODO: Set to 'http://mygemserver.com'"
21
- #
22
- # spec.metadata["homepage_uri"] = spec.homepage
23
- # spec.metadata["source_code_uri"] = "TODO: Put your gem's public repo URL here."
24
- # spec.metadata["changelog_uri"] = "TODO: Put your gem's CHANGELOG.md URL here."
25
- # else
26
- # raise "RubyGems 2.0 or newer is required to protect against " \
27
- # "public gem pushes."
28
- # end
29
-
30
17
  # Specify which files should be added to the gem when it is released.
31
18
  # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
32
19
  spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
@@ -38,7 +25,7 @@ Gem::Specification.new do |spec|
38
25
  spec.add_dependency "pagy"
39
26
  spec.add_dependency "activerecord", ">= 5"
40
27
 
41
- spec.add_development_dependency "bundler", "~> 1.17"
42
- spec.add_development_dependency "rake", "~> 10.0"
28
+ spec.add_development_dependency "bundler", "~> 2.0"
29
+ spec.add_development_dependency "rake", "~> 13.0"
43
30
  spec.add_development_dependency "rspec", "~> 3.0"
44
31
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pagy_cursor
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Uysim
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-02-04 00:00:00.000000000 Z
11
+ date: 2020-05-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: pagy
@@ -44,28 +44,28 @@ dependencies:
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: '1.17'
47
+ version: '2.0'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: '1.17'
54
+ version: '2.0'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: rake
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
59
  - - "~>"
60
60
  - !ruby/object:Gem::Version
61
- version: '10.0'
61
+ version: '13.0'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
- version: '10.0'
68
+ version: '13.0'
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: rspec
71
71
  requirement: !ruby/object:Gem::Requirement
@@ -87,10 +87,12 @@ executables: []
87
87
  extensions: []
88
88
  extra_rdoc_files: []
89
89
  files:
90
+ - ".github/workflows/gempush.yml"
90
91
  - ".gitignore"
91
92
  - ".rspec"
92
- - ".travis.yml"
93
93
  - CODE_OF_CONDUCT.md
94
+ - Gemfile
95
+ - Gemfile.lock
94
96
  - LICENSE.txt
95
97
  - README.md
96
98
  - Rakefile
@@ -99,6 +101,7 @@ files:
99
101
  - gemfiles/active_record_50.gemfile
100
102
  - gemfiles/active_record_51.gemfile
101
103
  - gemfiles/active_record_52.gemfile
104
+ - gemfiles/active_record_60.gemfile
102
105
  - lib/pagy_cursor.rb
103
106
  - lib/pagy_cursor/pagy/cursor.rb
104
107
  - lib/pagy_cursor/pagy/extras/cursor.rb
@@ -124,8 +127,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
124
127
  - !ruby/object:Gem::Version
125
128
  version: '0'
126
129
  requirements: []
127
- rubyforge_project:
128
- rubygems_version: 2.7.6
130
+ rubygems_version: 3.0.3
129
131
  signing_key:
130
132
  specification_version: 4
131
133
  summary: cursor paginations for pagy
@@ -1,29 +0,0 @@
1
-
2
- sudo: false
3
-
4
- language: ruby
5
-
6
- cache: bundler
7
-
8
- services:
9
- - postgresql
10
- - mysql
11
-
12
- rvm:
13
- - 2.6.3
14
- - 2.5.5
15
- - 2.4.5
16
- - 2.3.8
17
-
18
- gemfile:
19
- - gemfiles/active_record_52.gemfile
20
- - gemfiles/active_record_51.gemfile
21
- - gemfiles/active_record_50.gemfile
22
-
23
- env:
24
- - DB=sqlite3
25
- - DB=postgresql
26
- - DB=mysql
27
-
28
- before_install: gem install bundler -v 1.17.3
29
- script: bundle exec rspec