sortable-by 0.13.0 → 0.13.3

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4639f942b5f628b07367a343160d7e4301b00bf3c6e0db9f57ff43d204a85ab5
4
- data.tar.gz: 2f424ec2cda37112ca64fdf628b7ff0aee3e223dbee81d585040eff79ee468c8
3
+ metadata.gz: 739ba7b6c67825b04f539ac5f288617865cf98e0286b5504d561580e0b4a4da7
4
+ data.tar.gz: 9790f0fb3506dbe02f83a5a1fb312d568e0f3b4bcdb7265da896604f7ff398b9
5
5
  SHA512:
6
- metadata.gz: ff08a62e083e324f9baa4118423c82d90ad93d00f42b4cd6ae74d915a637439315f4cf5ebd8b9d598075bd9565064429a06d0017bae3b5f7998c35b39a50f14c
7
- data.tar.gz: b084242394054b896d594c923e262c6325a74c58c836e2224ee5c4f91c3bc087bedfe0b42eb7aa2438ea2a84dd41ddd54c6b5718f68e181d5869bbb5efcb2397
6
+ metadata.gz: 265748bb3409aed86fa24dd6b46102967408b50bb663b682d2a834ca36cc0c5694ad2dcf266f6d7e2751c4667ab975c539831df2d829a8fab9c88c6483a1edf9
7
+ data.tar.gz: a67635307cbafedaaf385d0a340e7745031a3e4439d5cd1f112400a6649f8762bf88e54f6655006550bf448b35a8ea60a47bee837f58e6a7168f0518c12c4bfd
@@ -0,0 +1,24 @@
1
+ name: Test
2
+
3
+ on:
4
+ push:
5
+ branches: [main]
6
+ pull_request:
7
+ branches: [main]
8
+
9
+ jobs:
10
+ ruby:
11
+ runs-on: ubuntu-latest
12
+ strategy:
13
+ matrix:
14
+ ruby-version: ["2.7", "3.0", "3.1"]
15
+ gemfiles: ["Gemfile", "Gemfile.rails6"]
16
+ env:
17
+ BUNDLE_GEMFILE: ${{ matrix.gemfile }}
18
+ steps:
19
+ - uses: actions/checkout@v2
20
+ - uses: ruby/setup-ruby@v1
21
+ with:
22
+ ruby-version: ${{ matrix.ruby-version }}
23
+ bundler-cache: true
24
+ - run: bundle exec rake
data/.rubocop.yml CHANGED
@@ -1,9 +1,12 @@
1
- inherit_from:
2
- - https://gitlab.com/bsm/misc/raw/master/rubocop/default.yml
1
+ inherit_gem:
2
+ rubocop-bsm:
3
+ - default.yml
4
+ inherit_mode:
5
+ merge:
6
+ - Exclude
3
7
 
4
8
  AllCops:
5
- TargetRubyVersion: 2.5
6
-
9
+ TargetRubyVersion: 2.7
7
10
  Naming/MethodParameterName:
8
11
  MinNameLength: 2
9
12
  Naming/MemoizedInstanceVariableName:
data/Gemfile.lock CHANGED
@@ -1,68 +1,77 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- sortable-by (0.13.0)
4
+ sortable-by (0.13.3)
5
5
  activerecord
6
6
  activesupport
7
7
 
8
8
  GEM
9
9
  remote: http://rubygems.org/
10
10
  specs:
11
- activemodel (6.0.3.3)
12
- activesupport (= 6.0.3.3)
13
- activerecord (6.0.3.3)
14
- activemodel (= 6.0.3.3)
15
- activesupport (= 6.0.3.3)
16
- activesupport (6.0.3.3)
11
+ activemodel (7.0.2.3)
12
+ activesupport (= 7.0.2.3)
13
+ activerecord (7.0.2.3)
14
+ activemodel (= 7.0.2.3)
15
+ activesupport (= 7.0.2.3)
16
+ activesupport (7.0.2.3)
17
17
  concurrent-ruby (~> 1.0, >= 1.0.2)
18
- i18n (>= 0.7, < 2)
19
- minitest (~> 5.1)
20
- tzinfo (~> 1.1)
21
- zeitwerk (~> 2.2, >= 2.2.2)
22
- ast (2.4.1)
23
- concurrent-ruby (1.1.7)
24
- diff-lcs (1.4.4)
25
- i18n (1.8.5)
18
+ i18n (>= 1.6, < 2)
19
+ minitest (>= 5.1)
20
+ tzinfo (~> 2.0)
21
+ ast (2.4.2)
22
+ concurrent-ruby (1.1.9)
23
+ diff-lcs (1.5.0)
24
+ i18n (1.10.0)
26
25
  concurrent-ruby (~> 1.0)
27
- minitest (5.14.2)
28
- parallel (1.19.2)
29
- parser (2.7.2.0)
26
+ minitest (5.15.0)
27
+ parallel (1.21.0)
28
+ parser (3.1.1.0)
30
29
  ast (~> 2.4.1)
31
- rainbow (3.0.0)
32
- rake (13.0.1)
33
- regexp_parser (1.8.1)
34
- rexml (3.2.4)
35
- rspec (3.9.0)
36
- rspec-core (~> 3.9.0)
37
- rspec-expectations (~> 3.9.0)
38
- rspec-mocks (~> 3.9.0)
39
- rspec-core (3.9.3)
40
- rspec-support (~> 3.9.3)
41
- rspec-expectations (3.9.2)
30
+ rainbow (3.1.1)
31
+ rake (13.0.6)
32
+ regexp_parser (2.2.1)
33
+ rexml (3.2.5)
34
+ rspec (3.11.0)
35
+ rspec-core (~> 3.11.0)
36
+ rspec-expectations (~> 3.11.0)
37
+ rspec-mocks (~> 3.11.0)
38
+ rspec-core (3.11.0)
39
+ rspec-support (~> 3.11.0)
40
+ rspec-expectations (3.11.0)
42
41
  diff-lcs (>= 1.2.0, < 2.0)
43
- rspec-support (~> 3.9.0)
44
- rspec-mocks (3.9.1)
42
+ rspec-support (~> 3.11.0)
43
+ rspec-mocks (3.11.0)
45
44
  diff-lcs (>= 1.2.0, < 2.0)
46
- rspec-support (~> 3.9.0)
47
- rspec-support (3.9.3)
48
- rubocop (0.92.0)
45
+ rspec-support (~> 3.11.0)
46
+ rspec-support (3.11.0)
47
+ rubocop (1.26.0)
49
48
  parallel (~> 1.10)
50
- parser (>= 2.7.1.5)
49
+ parser (>= 3.1.0.0)
51
50
  rainbow (>= 2.2.2, < 4.0)
52
- regexp_parser (>= 1.7)
51
+ regexp_parser (>= 1.8, < 3.0)
53
52
  rexml
54
- rubocop-ast (>= 0.5.0)
53
+ rubocop-ast (>= 1.16.0, < 2.0)
55
54
  ruby-progressbar (~> 1.7)
56
- unicode-display_width (>= 1.4.0, < 2.0)
57
- rubocop-ast (0.7.1)
58
- parser (>= 2.7.1.5)
59
- ruby-progressbar (1.10.1)
55
+ unicode-display_width (>= 1.4.0, < 3.0)
56
+ rubocop-ast (1.16.0)
57
+ parser (>= 3.1.1.0)
58
+ rubocop-bsm (0.6.0)
59
+ rubocop (~> 1.0)
60
+ rubocop-performance
61
+ rubocop-rake
62
+ rubocop-rspec
63
+ rubocop-performance (1.13.3)
64
+ rubocop (>= 1.7.0, < 2.0)
65
+ rubocop-ast (>= 0.4.0)
66
+ rubocop-rake (0.6.0)
67
+ rubocop (~> 1.0)
68
+ rubocop-rspec (2.9.0)
69
+ rubocop (~> 1.19)
70
+ ruby-progressbar (1.11.0)
60
71
  sqlite3 (1.4.2)
61
- thread_safe (0.3.6)
62
- tzinfo (1.2.7)
63
- thread_safe (~> 0.1)
64
- unicode-display_width (1.7.0)
65
- zeitwerk (2.4.0)
72
+ tzinfo (2.0.4)
73
+ concurrent-ruby (~> 1.0)
74
+ unicode-display_width (2.1.0)
66
75
 
67
76
  PLATFORMS
68
77
  ruby
@@ -71,9 +80,9 @@ DEPENDENCIES
71
80
  bundler
72
81
  rake
73
82
  rspec
74
- rubocop
83
+ rubocop-bsm
75
84
  sortable-by!
76
85
  sqlite3
77
86
 
78
87
  BUNDLED WITH
79
- 2.1.4
88
+ 2.3.9
data/Gemfile.rails6 ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+ gemspec
3
+
4
+ gem 'activerecord', '~> 6.1'
@@ -0,0 +1,91 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ sortable-by (0.13.3)
5
+ activerecord
6
+ activesupport
7
+
8
+ GEM
9
+ remote: https://rubygems.org/
10
+ specs:
11
+ activemodel (6.1.4.7)
12
+ activesupport (= 6.1.4.7)
13
+ activerecord (6.1.4.7)
14
+ activemodel (= 6.1.4.7)
15
+ activesupport (= 6.1.4.7)
16
+ activesupport (6.1.4.7)
17
+ concurrent-ruby (~> 1.0, >= 1.0.2)
18
+ i18n (>= 1.6, < 2)
19
+ minitest (>= 5.1)
20
+ tzinfo (~> 2.0)
21
+ zeitwerk (~> 2.3)
22
+ ast (2.4.2)
23
+ concurrent-ruby (1.1.9)
24
+ diff-lcs (1.5.0)
25
+ i18n (1.10.0)
26
+ concurrent-ruby (~> 1.0)
27
+ minitest (5.15.0)
28
+ parallel (1.21.0)
29
+ parser (3.1.1.0)
30
+ ast (~> 2.4.1)
31
+ rainbow (3.1.1)
32
+ rake (13.0.6)
33
+ regexp_parser (2.2.1)
34
+ rexml (3.2.5)
35
+ rspec (3.11.0)
36
+ rspec-core (~> 3.11.0)
37
+ rspec-expectations (~> 3.11.0)
38
+ rspec-mocks (~> 3.11.0)
39
+ rspec-core (3.11.0)
40
+ rspec-support (~> 3.11.0)
41
+ rspec-expectations (3.11.0)
42
+ diff-lcs (>= 1.2.0, < 2.0)
43
+ rspec-support (~> 3.11.0)
44
+ rspec-mocks (3.11.0)
45
+ diff-lcs (>= 1.2.0, < 2.0)
46
+ rspec-support (~> 3.11.0)
47
+ rspec-support (3.11.0)
48
+ rubocop (1.26.0)
49
+ parallel (~> 1.10)
50
+ parser (>= 3.1.0.0)
51
+ rainbow (>= 2.2.2, < 4.0)
52
+ regexp_parser (>= 1.8, < 3.0)
53
+ rexml
54
+ rubocop-ast (>= 1.16.0, < 2.0)
55
+ ruby-progressbar (~> 1.7)
56
+ unicode-display_width (>= 1.4.0, < 3.0)
57
+ rubocop-ast (1.16.0)
58
+ parser (>= 3.1.1.0)
59
+ rubocop-bsm (0.6.0)
60
+ rubocop (~> 1.0)
61
+ rubocop-performance
62
+ rubocop-rake
63
+ rubocop-rspec
64
+ rubocop-performance (1.13.3)
65
+ rubocop (>= 1.7.0, < 2.0)
66
+ rubocop-ast (>= 0.4.0)
67
+ rubocop-rake (0.6.0)
68
+ rubocop (~> 1.0)
69
+ rubocop-rspec (2.9.0)
70
+ rubocop (~> 1.19)
71
+ ruby-progressbar (1.11.0)
72
+ sqlite3 (1.4.2)
73
+ tzinfo (2.0.4)
74
+ concurrent-ruby (~> 1.0)
75
+ unicode-display_width (2.1.0)
76
+ zeitwerk (2.5.4)
77
+
78
+ PLATFORMS
79
+ x86_64-linux
80
+
81
+ DEPENDENCIES
82
+ activerecord (~> 6.1)
83
+ bundler
84
+ rake
85
+ rspec
86
+ rubocop-bsm
87
+ sortable-by!
88
+ sqlite3
89
+
90
+ BUNDLED WITH
91
+ 2.3.9
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Sortable By
2
2
 
3
- [![Build Status](https://travis-ci.org/bsm/sortable-by.png?branch=master)](https://travis-ci.org/bsm/sortable-by)
3
+ [![Test](https://github.com/bsm/sortable-by/actions/workflows/test.yml/badge.svg)](https://github.com/bsm/sortable-by/actions/workflows/test.yml)
4
4
  [![License](https://img.shields.io/badge/License-MIT-blue.svg)](https://opensource.org/licenses/MIT)
5
5
 
6
6
  ActiveRecord plugin to parse the sort order from a query parameter, match against a white-list and generate a scope. Useful for [JSON-API][jsonapi] compatibility.
@@ -20,10 +20,12 @@ class Post < ActiveRecord::Base
20
20
  sortable_by :title, :id
21
21
  end
22
22
 
23
- Post.sorted_by('title') # => ORDER BY LOWER(posts.title) ASC
24
- Post.sorted_by('-title') # => ORDER BY LOWER(posts.title) DESC
25
- Post.sorted_by('bad,title') # => ORDER BY LOWER(posts.title) ASC
26
- Post.sorted_by(nil) # => ORDER BY LOWER(posts.title) ASC
23
+ Post.sorted_by('title') # => ORDER BY LOWER(posts.title) ASC
24
+ Post.sorted_by('-title') # => ORDER BY LOWER(posts.title) DESC
25
+ Post.sorted_by('title,-id') # => ORDER BY LOWER(posts.title) ASC, id DESC
26
+ Post.sorted_by(['title', '-id']) # => ORDER BY LOWER(posts.title) ASC, id DESC
27
+ Post.sorted_by('bad,title') # => ORDER BY LOWER(posts.title) ASC
28
+ Post.sorted_by(nil) # => ORDER BY LOWER(posts.title) ASC
27
29
  ```
28
30
 
29
31
  Case-sensitive:
data/lib/sortable_by.rb CHANGED
@@ -38,13 +38,13 @@ module ActiveRecord # :nodoc:
38
38
 
39
39
  def order(relation, expr, fallback: true)
40
40
  matched = false
41
- expr.to_s.split(',').each do |name|
41
+ Array.wrap(expr).flat_map {|v| v.to_s.split(',') }.each do |name|
42
42
  name.strip!
43
43
 
44
44
  rank = :asc
45
45
  if name[0] == '-'
46
46
  rank = :desc
47
- name = name[1..-1]
47
+ name = name[1..]
48
48
  end
49
49
 
50
50
  field = _fields[name]
data/sortable-by.gemspec CHANGED
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'sortable-by'
3
- s.version = '0.13.0'
3
+ s.version = '0.13.3'
4
4
  s.authors = ['Dimitrij Denissenko']
5
5
  s.email = ['dimitrij@blacksquaremedia.com']
6
6
  s.summary = 'Generate white-listed sort scopes from URL parameter values'
@@ -11,7 +11,7 @@ Gem::Specification.new do |s|
11
11
  s.files = `git ls-files -z`.split("\x0").reject {|f| f.match(%r{^spec/}) }
12
12
  s.test_files = `git ls-files -z -- spec/*`.split("\x0")
13
13
  s.require_paths = ['lib']
14
- s.required_ruby_version = '>= 2.5'
14
+ s.required_ruby_version = '>= 2.7'
15
15
 
16
16
  s.add_dependency 'activerecord'
17
17
  s.add_dependency 'activesupport'
@@ -19,6 +19,7 @@ Gem::Specification.new do |s|
19
19
  s.add_development_dependency 'bundler'
20
20
  s.add_development_dependency 'rake'
21
21
  s.add_development_dependency 'rspec'
22
- s.add_development_dependency 'rubocop'
22
+ s.add_development_dependency 'rubocop-bsm'
23
23
  s.add_development_dependency 'sqlite3'
24
+ s.metadata['rubygems_mfa_required'] = 'true'
24
25
  end
@@ -1,4 +1,4 @@
1
- require File.expand_path('./spec_helper', __dir__)
1
+ require 'spec_helper'
2
2
 
3
3
  describe ActiveRecord::SortableBy do
4
4
  before do
@@ -8,7 +8,7 @@ describe ActiveRecord::SortableBy do
8
8
  end
9
9
  end
10
10
 
11
- it 'should have config' do
11
+ it 'has config' do
12
12
  expect(Post._sortable_by_config._fields.keys).to match_array(%w[title created])
13
13
  expect(Post._sortable_by_config._default).to eq('-created')
14
14
  expect(SubPost._sortable_by_config._fields.keys).to match_array(%w[title created])
@@ -24,7 +24,7 @@ describe ActiveRecord::SortableBy do
24
24
  expect(Product._sortable_by_config._default).to eq('shop,name')
25
25
  end
26
26
 
27
- it 'should simply order' do
27
+ it 'supports simple ordering' do
28
28
  Post.create! title: 'A', created_at: Time.at(1515151500)
29
29
  Post.create! title: 'b', created_at: Time.at(1515151600)
30
30
  Post.create! title: 'C', created_at: Time.at(1515151400)
@@ -41,7 +41,16 @@ describe ActiveRecord::SortableBy do
41
41
  expect(Post.sorted_by(' title ').pluck(:title)).to eq(%w[A C b])
42
42
  end
43
43
 
44
- it 'should support STI inheritance and overrides' do
44
+ it 'supports array params' do
45
+ Post.create! title: 'A', created_at: Time.at(1515151500)
46
+ Post.create! title: 'C', created_at: Time.at(1515151400)
47
+ Post.create! title: 'B', created_at: Time.at(1515151400)
48
+
49
+ expect(Post.sorted_by(['created', '-title']).pluck(:title)).to eq(%w[C B A])
50
+ expect(Post.sorted_by(['created , -title']).pluck(:title)).to eq(%w[C B A])
51
+ end
52
+
53
+ it 'supports STI inheritance and overrides' do
45
54
  SubPost.create! title: 'A', created_at: Time.at(1515151700)
46
55
  SubPost.create! title: 'b', created_at: Time.at(1515151600)
47
56
  Post.create! title: 'C', created_at: Time.at(1515151400)
@@ -56,7 +65,7 @@ describe ActiveRecord::SortableBy do
56
65
  expect(SubPost.sorted_by('title').pluck(:title)).to eq(%w[A b D])
57
66
  end
58
67
 
59
- it 'should support composition' do
68
+ it 'supports composition' do
60
69
  App.create! name: 'E', major: 0, minor: 9, patch: 2
61
70
  App.create! name: 'A', major: 1, minor: 0, patch: 1
62
71
  App.create! name: 'D', major: 1, minor: 0, patch: 6
@@ -68,7 +77,7 @@ describe ActiveRecord::SortableBy do
68
77
  expect(App.sorted_by('-version').pluck(:name)).to eq(%w[B C D A E])
69
78
  end
70
79
 
71
- it 'should support associations' do
80
+ it 'supports associations' do
72
81
  y = Shop.create! name: 'Y'
73
82
  x = Shop.create! name: 'X'
74
83
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sortable-by
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.13.0
4
+ version: 0.13.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dimitrij Denissenko
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-10-07 00:00:00.000000000 Z
11
+ date: 2022-03-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -81,7 +81,7 @@ dependencies:
81
81
  - !ruby/object:Gem::Version
82
82
  version: '0'
83
83
  - !ruby/object:Gem::Dependency
84
- name: rubocop
84
+ name: rubocop-bsm
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
87
  - - ">="
@@ -115,23 +115,26 @@ executables: []
115
115
  extensions: []
116
116
  extra_rdoc_files: []
117
117
  files:
118
+ - ".github/workflows/test.yml"
118
119
  - ".gitignore"
119
120
  - ".rubocop.yml"
120
- - ".travis.yml"
121
121
  - Gemfile
122
122
  - Gemfile.lock
123
+ - Gemfile.rails6
124
+ - Gemfile.rails6.lock
123
125
  - LICENSE
124
126
  - README.md
125
127
  - Rakefile
126
128
  - lib/sortable-by.rb
127
129
  - lib/sortable_by.rb
128
130
  - sortable-by.gemspec
129
- - spec/sortable_by_spec.rb
131
+ - spec/active_record/sortable_by_spec.rb
130
132
  - spec/spec_helper.rb
131
133
  homepage: https://github.com/bsm/sortable-by
132
134
  licenses:
133
135
  - MIT
134
- metadata: {}
136
+ metadata:
137
+ rubygems_mfa_required: 'true'
135
138
  post_install_message:
136
139
  rdoc_options: []
137
140
  require_paths:
@@ -140,17 +143,17 @@ required_ruby_version: !ruby/object:Gem::Requirement
140
143
  requirements:
141
144
  - - ">="
142
145
  - !ruby/object:Gem::Version
143
- version: '2.5'
146
+ version: '2.7'
144
147
  required_rubygems_version: !ruby/object:Gem::Requirement
145
148
  requirements:
146
149
  - - ">="
147
150
  - !ruby/object:Gem::Version
148
151
  version: '0'
149
152
  requirements: []
150
- rubygems_version: 3.1.2
153
+ rubygems_version: 3.3.3
151
154
  signing_key:
152
155
  specification_version: 4
153
156
  summary: Generate white-listed sort scopes from URL parameter values
154
157
  test_files:
155
- - spec/sortable_by_spec.rb
158
+ - spec/active_record/sortable_by_spec.rb
156
159
  - spec/spec_helper.rb
data/.travis.yml DELETED
@@ -1,9 +0,0 @@
1
- sudo: false
2
- rvm:
3
- - 2.5
4
- - 2.6
5
- - 2.7
6
- gemfile:
7
- - Gemfile
8
- before_install:
9
- - gem install bundler