sortable-by 0.11.1 → 0.13.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/test.yml +21 -0
- data/.rubocop.yml +9 -4
- data/Gemfile.lock +62 -45
- data/README.md +15 -13
- data/lib/sortable_by.rb +24 -19
- data/sortable-by.gemspec +3 -3
- data/spec/{sortable_by_spec.rb → active_record/sortable_by_spec.rb} +15 -6
- data/spec/spec_helper.rb +9 -7
- metadata +8 -8
- data/.travis.yml +0 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6412f520dea934585eaa16b0ec4f4b45fb088ed0274057de0c9c4ad38bd05d2c
|
4
|
+
data.tar.gz: 76a714b65c57e5c3b56ded227be2cfe80f66e469435b3d7f0c94bd11f1364493
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: eefaafc008737c4f728164566d6a73a23fb845f04e84660eed18b6ba9770c8b3649c4d7d26b7376cf1f2b24e84e5054bed6038cf0a6ad863cce5db2985dc804d
|
7
|
+
data.tar.gz: 06acb810e43171c8a8e3687c9ebfde4f193750aed2449b5360d7bcc9bffb660b7dc574cbd01f1b6af8923dfb3b7a5bb873a1532f4227b8e16c4a18a770bd2095
|
@@ -0,0 +1,21 @@
|
|
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.6", "2.7", "3.0"]
|
15
|
+
steps:
|
16
|
+
- uses: actions/checkout@v2
|
17
|
+
- uses: ruby/setup-ruby@v1
|
18
|
+
with:
|
19
|
+
ruby-version: ${{ matrix.ruby-version }}
|
20
|
+
bundler-cache: true
|
21
|
+
- run: bundle exec rake
|
data/.rubocop.yml
CHANGED
@@ -1,9 +1,14 @@
|
|
1
|
-
|
2
|
-
-
|
1
|
+
inherit_gem:
|
2
|
+
rubocop-bsm:
|
3
|
+
- default.yml
|
4
|
+
inherit_mode:
|
5
|
+
merge:
|
6
|
+
- Exclude
|
3
7
|
|
4
8
|
AllCops:
|
5
|
-
TargetRubyVersion: 2.
|
6
|
-
|
9
|
+
TargetRubyVersion: 2.6
|
10
|
+
Naming/MethodParameterName:
|
11
|
+
MinNameLength: 2
|
7
12
|
Naming/MemoizedInstanceVariableName:
|
8
13
|
Enabled: false
|
9
14
|
Naming/FileName:
|
data/Gemfile.lock
CHANGED
@@ -1,63 +1,80 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
sortable-by (0.
|
4
|
+
sortable-by (0.13.2)
|
5
5
|
activerecord
|
6
6
|
activesupport
|
7
7
|
|
8
8
|
GEM
|
9
9
|
remote: http://rubygems.org/
|
10
10
|
specs:
|
11
|
-
activemodel (
|
12
|
-
activesupport (=
|
13
|
-
activerecord (
|
14
|
-
activemodel (=
|
15
|
-
activesupport (=
|
16
|
-
|
17
|
-
activesupport (5.2.3)
|
11
|
+
activemodel (6.1.3.2)
|
12
|
+
activesupport (= 6.1.3.2)
|
13
|
+
activerecord (6.1.3.2)
|
14
|
+
activemodel (= 6.1.3.2)
|
15
|
+
activesupport (= 6.1.3.2)
|
16
|
+
activesupport (6.1.3.2)
|
18
17
|
concurrent-ruby (~> 1.0, >= 1.0.2)
|
19
|
-
i18n (>=
|
20
|
-
minitest (
|
21
|
-
tzinfo (~>
|
22
|
-
|
23
|
-
ast (2.4.
|
24
|
-
concurrent-ruby (1.1.
|
25
|
-
diff-lcs (1.
|
26
|
-
i18n (1.
|
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.8)
|
24
|
+
diff-lcs (1.4.4)
|
25
|
+
i18n (1.8.10)
|
27
26
|
concurrent-ruby (~> 1.0)
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
ast (~> 2.4.0)
|
27
|
+
minitest (5.14.4)
|
28
|
+
parallel (1.20.1)
|
29
|
+
parser (3.0.1.1)
|
30
|
+
ast (~> 2.4.1)
|
33
31
|
rainbow (3.0.0)
|
34
|
-
rake (
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
rspec-
|
39
|
-
|
40
|
-
rspec-
|
41
|
-
rspec-
|
32
|
+
rake (13.0.3)
|
33
|
+
regexp_parser (2.1.1)
|
34
|
+
rexml (3.2.5)
|
35
|
+
rspec (3.10.0)
|
36
|
+
rspec-core (~> 3.10.0)
|
37
|
+
rspec-expectations (~> 3.10.0)
|
38
|
+
rspec-mocks (~> 3.10.0)
|
39
|
+
rspec-core (3.10.1)
|
40
|
+
rspec-support (~> 3.10.0)
|
41
|
+
rspec-expectations (3.10.1)
|
42
42
|
diff-lcs (>= 1.2.0, < 2.0)
|
43
|
-
rspec-support (~> 3.
|
44
|
-
rspec-mocks (3.
|
43
|
+
rspec-support (~> 3.10.0)
|
44
|
+
rspec-mocks (3.10.2)
|
45
45
|
diff-lcs (>= 1.2.0, < 2.0)
|
46
|
-
rspec-support (~> 3.
|
47
|
-
rspec-support (3.
|
48
|
-
rubocop (
|
49
|
-
jaro_winkler (~> 1.5.1)
|
46
|
+
rspec-support (~> 3.10.0)
|
47
|
+
rspec-support (3.10.2)
|
48
|
+
rubocop (1.16.0)
|
50
49
|
parallel (~> 1.10)
|
51
|
-
parser (>=
|
50
|
+
parser (>= 3.0.0.0)
|
52
51
|
rainbow (>= 2.2.2, < 4.0)
|
52
|
+
regexp_parser (>= 1.8, < 3.0)
|
53
|
+
rexml
|
54
|
+
rubocop-ast (>= 1.7.0, < 2.0)
|
53
55
|
ruby-progressbar (~> 1.7)
|
54
|
-
unicode-display_width (>= 1.4.0, <
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
56
|
+
unicode-display_width (>= 1.4.0, < 3.0)
|
57
|
+
rubocop-ast (1.7.0)
|
58
|
+
parser (>= 3.0.1.1)
|
59
|
+
rubocop-bsm (0.6.0)
|
60
|
+
rubocop (~> 1.0)
|
61
|
+
rubocop-performance
|
62
|
+
rubocop-rake
|
63
|
+
rubocop-rspec
|
64
|
+
rubocop-performance (1.11.3)
|
65
|
+
rubocop (>= 1.7.0, < 2.0)
|
66
|
+
rubocop-ast (>= 0.4.0)
|
67
|
+
rubocop-rake (0.5.1)
|
68
|
+
rubocop
|
69
|
+
rubocop-rspec (2.3.0)
|
70
|
+
rubocop (~> 1.0)
|
71
|
+
rubocop-ast (>= 1.1.0)
|
72
|
+
ruby-progressbar (1.11.0)
|
73
|
+
sqlite3 (1.4.2)
|
74
|
+
tzinfo (2.0.4)
|
75
|
+
concurrent-ruby (~> 1.0)
|
76
|
+
unicode-display_width (2.0.0)
|
77
|
+
zeitwerk (2.4.2)
|
61
78
|
|
62
79
|
PLATFORMS
|
63
80
|
ruby
|
@@ -66,9 +83,9 @@ DEPENDENCIES
|
|
66
83
|
bundler
|
67
84
|
rake
|
68
85
|
rspec
|
69
|
-
rubocop
|
86
|
+
rubocop-bsm
|
70
87
|
sortable-by!
|
71
88
|
sqlite3
|
72
89
|
|
73
90
|
BUNDLED WITH
|
74
|
-
|
91
|
+
2.2.19
|
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# Sortable By
|
2
2
|
|
3
|
-
[![
|
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,23 +20,25 @@ class Post < ActiveRecord::Base
|
|
20
20
|
sortable_by :title, :id
|
21
21
|
end
|
22
22
|
|
23
|
-
Post.sorted_by('title')
|
24
|
-
Post.sorted_by('-title')
|
25
|
-
Post.sorted_by('
|
26
|
-
Post.sorted_by(
|
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
|
-
Case-
|
31
|
+
Case-sensitive:
|
30
32
|
|
31
33
|
```ruby
|
32
34
|
class Post < ActiveRecord::Base
|
33
35
|
sortable_by do |x|
|
34
|
-
x.field :title,
|
36
|
+
x.field :title, case_sensitive: true
|
35
37
|
x.field :id
|
36
38
|
end
|
37
39
|
end
|
38
40
|
|
39
|
-
Post.sorted_by('title') # => ORDER BY
|
41
|
+
Post.sorted_by('title') # => ORDER BY posts.title ASC
|
40
42
|
```
|
41
43
|
|
42
44
|
With custom default:
|
@@ -46,7 +48,7 @@ class Post < ActiveRecord::Base
|
|
46
48
|
sortable_by :id, :topic, :created_at, default: 'topic,-created_at'
|
47
49
|
end
|
48
50
|
|
49
|
-
Post.sorted_by(nil) # => ORDER BY posts.topic ASC, posts.created_at DESC
|
51
|
+
Post.sorted_by(nil) # => ORDER BY LOWER(posts.topic) ASC, posts.created_at DESC
|
50
52
|
```
|
51
53
|
|
52
54
|
Composition:
|
@@ -68,8 +70,8 @@ Associations (eager load):
|
|
68
70
|
class Product < ActiveRecord::Base
|
69
71
|
belongs_to :shop
|
70
72
|
sortable_by do |x|
|
71
|
-
x.field :name
|
72
|
-
x.field :shop, as: Shop.arel_table[:name]
|
73
|
+
x.field :name
|
74
|
+
x.field :shop, as: Shop.arel_table[:name], eager_load: :shop
|
73
75
|
x.default 'shop,name'
|
74
76
|
end
|
75
77
|
end
|
@@ -77,11 +79,11 @@ end
|
|
77
79
|
|
78
80
|
Associations (custom scope):
|
79
81
|
|
80
|
-
```
|
82
|
+
```ruby
|
81
83
|
class Product < ActiveRecord::Base
|
82
84
|
belongs_to :shop
|
83
85
|
sortable_by do |x|
|
84
|
-
x.field :shop, as: Shop.arel_table[:name]
|
86
|
+
x.field :shop, as: Shop.arel_table[:name], scope: -> { joins(:shop) }
|
85
87
|
end
|
86
88
|
end
|
87
89
|
```
|
data/lib/sortable_by.rb
CHANGED
@@ -17,9 +17,9 @@ module ActiveRecord # :nodoc:
|
|
17
17
|
duplicate
|
18
18
|
end
|
19
19
|
|
20
|
-
def field(name, opts
|
20
|
+
def field(name, **opts)
|
21
21
|
name = name.to_s
|
22
|
-
@_fields[name] = Field.new(name, opts)
|
22
|
+
@_fields[name] = Field.new(name, **opts)
|
23
23
|
@_default ||= name
|
24
24
|
end
|
25
25
|
|
@@ -36,36 +36,39 @@ module ActiveRecord # :nodoc:
|
|
36
36
|
|
37
37
|
protected
|
38
38
|
|
39
|
-
def order(relation, expr, fallback
|
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
|
47
|
+
name = name[1..]
|
48
48
|
end
|
49
49
|
|
50
50
|
field = _fields[name]
|
51
51
|
next unless field
|
52
52
|
|
53
|
-
matched
|
53
|
+
matched = true
|
54
54
|
relation = field.order(relation, rank)
|
55
55
|
end
|
56
56
|
|
57
|
-
relation = order(relation, _default, false) if fallback && !matched && _default
|
57
|
+
relation = order(relation, _default, fallback: false) if fallback && !matched && _default
|
58
58
|
relation
|
59
59
|
end
|
60
60
|
end
|
61
61
|
|
62
62
|
class Field # :nodoc:
|
63
|
-
|
64
|
-
|
65
|
-
|
63
|
+
STRING_TYPES = %i[string text].freeze # :nodoc:
|
64
|
+
|
65
|
+
def initialize(name, as: nil, scope: nil, eager_load: nil, case_sensitive: false)
|
66
|
+
@cols = Array.wrap(as)
|
67
|
+
@eager_load = Array.wrap(eager_load).presence
|
68
|
+
@case_sensitive = case_sensitive == true
|
66
69
|
|
67
70
|
# validate custom_scope
|
68
|
-
@custom_scope =
|
71
|
+
@custom_scope = scope
|
69
72
|
raise ArgumentError, "Invalid sortable-by field '#{name}': scope must be a Proc." if @custom_scope && !@custom_scope.is_a?(Proc)
|
70
73
|
|
71
74
|
# normalize cols
|
@@ -86,7 +89,10 @@ module ActiveRecord # :nodoc:
|
|
86
89
|
@cols.each do |col|
|
87
90
|
case col
|
88
91
|
when String, Symbol
|
89
|
-
|
92
|
+
type = relation.columns_hash[col.to_s].type
|
93
|
+
col = relation.arel_table[col]
|
94
|
+
col = col.lower if STRING_TYPES.include?(type) && !@case_sensitive
|
95
|
+
relation = relation.order(col.send(rank))
|
90
96
|
when Arel::Nodes::Node, Arel::Attributes::Attribute
|
91
97
|
relation = relation.order(col.send(rank))
|
92
98
|
when Proc
|
@@ -117,10 +123,10 @@ module ActiveRecord # :nodoc:
|
|
117
123
|
# sortable_by :title, :id
|
118
124
|
# end
|
119
125
|
#
|
120
|
-
# # Case-
|
126
|
+
# # Case-sensitive
|
121
127
|
# class Post < ActiveRecord::Base
|
122
128
|
# sortable_by do |x|
|
123
|
-
# x.field :title,
|
129
|
+
# x.field :title, case_sensitive: true
|
124
130
|
# x.field :id
|
125
131
|
# end
|
126
132
|
# end
|
@@ -144,7 +150,7 @@ module ActiveRecord # :nodoc:
|
|
144
150
|
#
|
145
151
|
# sortable_by do |x|
|
146
152
|
# x.field :name
|
147
|
-
# x.field :shop, as: Shop.arel_table[:name]
|
153
|
+
# x.field :shop, as: Shop.arel_table[:name], eager_load: :shop
|
148
154
|
# x.default 'shop,name'
|
149
155
|
# end
|
150
156
|
# end
|
@@ -154,17 +160,16 @@ module ActiveRecord # :nodoc:
|
|
154
160
|
# belongs_to :shop
|
155
161
|
#
|
156
162
|
# sortable_by do |x|
|
157
|
-
# x.field :shop, as: Shop.arel_table[:name]
|
163
|
+
# x.field :shop, as: Shop.arel_table[:name], scope: -> { joins(:shop) }
|
158
164
|
# end
|
159
165
|
# end
|
160
166
|
#
|
161
|
-
def sortable_by(*attributes)
|
167
|
+
def sortable_by(*attributes, **opts)
|
162
168
|
config = _sortable_by_config
|
163
|
-
opts = attributes.extract_options!
|
164
169
|
default = opts.delete(:default)
|
165
170
|
|
166
171
|
attributes.each do |name|
|
167
|
-
config.field(name, opts)
|
172
|
+
config.field(name, **opts)
|
168
173
|
end
|
169
174
|
config.default(default) if default
|
170
175
|
yield config if block_given?
|
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.
|
3
|
+
s.version = '0.13.2'
|
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.
|
14
|
+
s.required_ruby_version = '>= 2.6'
|
15
15
|
|
16
16
|
s.add_dependency 'activerecord'
|
17
17
|
s.add_dependency 'activesupport'
|
@@ -19,6 +19,6 @@ 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
24
|
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
require
|
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 '
|
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 '
|
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 '
|
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 '
|
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 '
|
80
|
+
it 'supports associations' do
|
72
81
|
y = Shop.create! name: 'Y'
|
73
82
|
x = Shop.create! name: 'X'
|
74
83
|
|
data/spec/spec_helper.rb
CHANGED
@@ -2,9 +2,11 @@ ENV['RACK_ENV'] ||= 'test'
|
|
2
2
|
require 'sortable-by'
|
3
3
|
require 'rspec'
|
4
4
|
|
5
|
-
ActiveRecord::Base.configurations
|
6
|
-
'
|
7
|
-
|
5
|
+
ActiveRecord::Base.configurations = {
|
6
|
+
'test' => {
|
7
|
+
'adapter' => 'sqlite3',
|
8
|
+
'database' => ':memory:',
|
9
|
+
},
|
8
10
|
}
|
9
11
|
ActiveRecord::Base.establish_connection :test
|
10
12
|
|
@@ -15,14 +17,14 @@ ActiveRecord::Base.connection.create_table :posts do |t|
|
|
15
17
|
end
|
16
18
|
|
17
19
|
class Post < ActiveRecord::Base
|
18
|
-
sortable_by :title, default: '-created' do |s|
|
20
|
+
sortable_by :title, default: '-created', case_sensitive: true do |s|
|
19
21
|
s.field :created, as: arel_table[:created_at]
|
20
22
|
end
|
21
23
|
end
|
22
24
|
|
23
25
|
class SubPost < Post
|
24
26
|
sortable_by do |s|
|
25
|
-
s.field :title
|
27
|
+
s.field :title
|
26
28
|
end
|
27
29
|
end
|
28
30
|
|
@@ -63,8 +65,8 @@ class Product < ActiveRecord::Base
|
|
63
65
|
belongs_to :shop
|
64
66
|
|
65
67
|
sortable_by do |s|
|
66
|
-
s.field :name
|
67
|
-
s.field :shop, as: Shop.arel_table[:name]
|
68
|
+
s.field :name
|
69
|
+
s.field :shop, as: Shop.arel_table[:name], eager_load: :shop
|
68
70
|
s.default 'shop,name'
|
69
71
|
end
|
70
72
|
end
|
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.
|
4
|
+
version: 0.13.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dimitrij Denissenko
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-06-03 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,9 +115,9 @@ 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
123
|
- LICENSE
|
@@ -126,7 +126,7 @@ files:
|
|
126
126
|
- lib/sortable-by.rb
|
127
127
|
- lib/sortable_by.rb
|
128
128
|
- sortable-by.gemspec
|
129
|
-
- spec/sortable_by_spec.rb
|
129
|
+
- spec/active_record/sortable_by_spec.rb
|
130
130
|
- spec/spec_helper.rb
|
131
131
|
homepage: https://github.com/bsm/sortable-by
|
132
132
|
licenses:
|
@@ -140,17 +140,17 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
140
140
|
requirements:
|
141
141
|
- - ">="
|
142
142
|
- !ruby/object:Gem::Version
|
143
|
-
version: '2.
|
143
|
+
version: '2.6'
|
144
144
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
145
145
|
requirements:
|
146
146
|
- - ">="
|
147
147
|
- !ruby/object:Gem::Version
|
148
148
|
version: '0'
|
149
149
|
requirements: []
|
150
|
-
rubygems_version: 3.
|
150
|
+
rubygems_version: 3.2.15
|
151
151
|
signing_key:
|
152
152
|
specification_version: 4
|
153
153
|
summary: Generate white-listed sort scopes from URL parameter values
|
154
154
|
test_files:
|
155
|
-
- spec/sortable_by_spec.rb
|
155
|
+
- spec/active_record/sortable_by_spec.rb
|
156
156
|
- spec/spec_helper.rb
|