activerecord-sort 6.0.0.2 → 6.1.0.rc1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +8 -8
- data/ext/active_record/base.rb +5 -6
- data/lib/active_record/sort.rb +1 -5
- data/lib/active_record/sort/version.rb +1 -1
- metadata +52 -15
- data/ext/arel/nodes/ascending.rb +0 -14
- data/ext/arel/nodes/descending.rb +0 -15
- data/ext/arel/nodes/random.rb +0 -7
- data/ext/arel/order_predications.rb +0 -14
- data/ext/arel/visitors/postgresql.rb +0 -28
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1845764483eacf7b3cce0ee2b9b7f3d1cff6d3d1211518f12e54be59a7cccf9f
|
4
|
+
data.tar.gz: d4072a886aaeed64c12d01a5ede815db50efe30823731c0e8fb6c0c69fd8e762
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4356863599576c5a49c4a720eb6fd1be043235532d606cde9a1592d562ea643d1fe1abe906dcdc6c5fa6ef65155917605904ec780fdabb24858e0171364e4971
|
7
|
+
data.tar.gz: 104bdf59db87f9781f002af1faf40834373fa07fda6887f666f5d9324c25ee74b31f48b4f3d4ba2819d2f259907a89eede04f3e3ce61f8ebd7db0e234d050b78
|
data/README.md
CHANGED
@@ -13,34 +13,34 @@ Examples
|
|
13
13
|
`ActiveRecord::sort` supports the following cases:
|
14
14
|
|
15
15
|
```ruby
|
16
|
-
Property.
|
16
|
+
Property.sort(:id).to_sql
|
17
17
|
# => "...ORDER BY properties.id ASC"
|
18
18
|
|
19
|
-
Property.
|
19
|
+
Property.sort(:id, :name).to_sql
|
20
20
|
# => "...ORDER BY properties.id ASC, properties.name ASC"
|
21
21
|
|
22
|
-
Property.
|
22
|
+
Property.sort(id: :desc).to_sql
|
23
23
|
# => "...ORDER BY properties.id DESC"
|
24
24
|
|
25
|
-
Property.
|
25
|
+
Property.sort(id: {asc: :nulls_first})
|
26
26
|
# => "...ORDER BY properties.id ASC NULLS FIRST"
|
27
27
|
|
28
|
-
Property.
|
28
|
+
Property.sort(id: {asc: :nulls_last})
|
29
29
|
# => "...ORDER BY properties.id ASC NULLS LAST"
|
30
30
|
```
|
31
31
|
|
32
32
|
It can also sort on relations:
|
33
33
|
|
34
34
|
```ruby
|
35
|
-
Property.
|
35
|
+
Property.sort(addresses: :id).to_sql
|
36
36
|
# => "...INNER JOIN addresses ON addresses.property_id = properties.id
|
37
37
|
# => " ORDER BY addresses.id ASC"
|
38
38
|
|
39
|
-
Property.
|
39
|
+
Property.sort(addresses: {id: :desc}).to_sql
|
40
40
|
# => "...INNER JOIN addresses ON addresses.property_id = properties.id
|
41
41
|
# => " ORDER BY addresses.id DESC"
|
42
42
|
|
43
|
-
Property.
|
43
|
+
Property.sort(addresses: {id: {asc: :nulls_frist}}).to_sql
|
44
44
|
# => "...INNER JOIN addresses ON addresses.property_id = properties.id
|
45
45
|
# => " ORDER BY addresses.id ASC NULLS FIRST"
|
46
46
|
```
|
data/ext/active_record/base.rb
CHANGED
@@ -26,7 +26,7 @@ module ActiveRecord
|
|
26
26
|
if column_or_relation.to_sym == :random
|
27
27
|
resource = resource.random_sort
|
28
28
|
elsif self.column_names.include?(column_or_relation.to_s)
|
29
|
-
resource = resource.sort_for_column(column_or_relation, options)
|
29
|
+
resource = resource.sort_for_column(self.arel_table[column_or_relation.to_s], options)
|
30
30
|
elsif reflect_on_association(column_or_relation.to_sym)
|
31
31
|
resource = resource.select(resource.klass.arel_table[Arel::Nodes::SqlLiteral.new('*')])
|
32
32
|
resource = resource.sort_for_relation(column_or_relation.to_sym, options)
|
@@ -45,8 +45,7 @@ module ActiveRecord
|
|
45
45
|
|
46
46
|
# TODO: probably don't need to cast to sym
|
47
47
|
def sort_for_column(column, options)
|
48
|
-
|
49
|
-
direction = (options.is_a?(Hash) || options.is_a?(ActionController::Parameters) ? options.keys.first.to_sym : options.to_s.downcase.to_sym)
|
48
|
+
direction = (options.is_a?(Hash) || options.class.name == "ActionController::Parameters" ? options.keys.first.to_sym : options.to_s.downcase.to_sym)
|
50
49
|
|
51
50
|
nulls = (options.is_a?(Hash) ? options.values.first.to_sym : nil)
|
52
51
|
if direction == :desc
|
@@ -68,7 +67,7 @@ module ActiveRecord
|
|
68
67
|
options.each do |order|
|
69
68
|
order = Array(order)
|
70
69
|
order.each do |column, options|
|
71
|
-
column = relation.klass.arel_table[column]
|
70
|
+
column = Arel::Attributes::Relation.new(relation.klass.arel_table[column], relation.name)
|
72
71
|
direction = (options.is_a?(Hash) ? options.keys.first.to_sym : options.to_s.downcase.to_sym)
|
73
72
|
|
74
73
|
nulls = (options.is_a?(Hash) ? options.values.first.to_sym : nil)
|
@@ -111,7 +110,7 @@ module ActiveRecord
|
|
111
110
|
order = Arel::Nodes::Descending.new(column, nulls)
|
112
111
|
end
|
113
112
|
|
114
|
-
resource = resource.
|
113
|
+
resource = resource.left_outer_joins(relation.name)
|
115
114
|
resource = resource.order(order)
|
116
115
|
end
|
117
116
|
end
|
@@ -121,4 +120,4 @@ module ActiveRecord
|
|
121
120
|
end
|
122
121
|
|
123
122
|
end
|
124
|
-
end
|
123
|
+
end
|
data/lib/active_record/sort.rb
CHANGED
@@ -1,10 +1,6 @@
|
|
1
1
|
require 'active_record'
|
2
|
+
require 'arel/extensions'
|
2
3
|
|
3
|
-
require File.expand_path(File.join(__FILE__, '../../../ext/arel/order_predications'))
|
4
|
-
require File.expand_path(File.join(__FILE__, '../../../ext/arel/nodes/ascending'))
|
5
|
-
require File.expand_path(File.join(__FILE__, '../../../ext/arel/nodes/descending'))
|
6
|
-
require File.expand_path(File.join(__FILE__, '../../../ext/arel/nodes/random'))
|
7
|
-
require File.expand_path(File.join(__FILE__, '../../../ext/arel/visitors/postgresql'))
|
8
4
|
require File.expand_path(File.join(__FILE__, '../../../ext/active_record/base'))
|
9
5
|
|
10
6
|
ActiveRecord::Querying.delegate :sort, to: :all
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: activerecord-sort
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 6.
|
4
|
+
version: 6.1.0.rc1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jon Bracy
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-12-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
@@ -16,14 +16,28 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: 6.
|
19
|
+
version: 6.1.0
|
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: 6.
|
26
|
+
version: 6.1.0
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: arel-extensions
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 6.1.0.rc2
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 6.1.0.rc2
|
27
41
|
- !ruby/object:Gem::Dependency
|
28
42
|
name: pg
|
29
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -136,6 +150,34 @@ dependencies:
|
|
136
150
|
- - ">="
|
137
151
|
- !ruby/object:Gem::Version
|
138
152
|
version: '0'
|
153
|
+
- !ruby/object:Gem::Dependency
|
154
|
+
name: sunstone
|
155
|
+
requirement: !ruby/object:Gem::Requirement
|
156
|
+
requirements:
|
157
|
+
- - ">="
|
158
|
+
- !ruby/object:Gem::Version
|
159
|
+
version: 6.1.0.rc1
|
160
|
+
type: :development
|
161
|
+
prerelease: false
|
162
|
+
version_requirements: !ruby/object:Gem::Requirement
|
163
|
+
requirements:
|
164
|
+
- - ">="
|
165
|
+
- !ruby/object:Gem::Version
|
166
|
+
version: 6.1.0.rc1
|
167
|
+
- !ruby/object:Gem::Dependency
|
168
|
+
name: webmock
|
169
|
+
requirement: !ruby/object:Gem::Requirement
|
170
|
+
requirements:
|
171
|
+
- - ">="
|
172
|
+
- !ruby/object:Gem::Version
|
173
|
+
version: '0'
|
174
|
+
type: :development
|
175
|
+
prerelease: false
|
176
|
+
version_requirements: !ruby/object:Gem::Requirement
|
177
|
+
requirements:
|
178
|
+
- - ">="
|
179
|
+
- !ruby/object:Gem::Version
|
180
|
+
version: '0'
|
139
181
|
description: A safe way to accept user parameters and order against your ActiveRecord
|
140
182
|
Models
|
141
183
|
email:
|
@@ -147,18 +189,13 @@ extra_rdoc_files:
|
|
147
189
|
files:
|
148
190
|
- README.md
|
149
191
|
- ext/active_record/base.rb
|
150
|
-
- ext/arel/nodes/ascending.rb
|
151
|
-
- ext/arel/nodes/descending.rb
|
152
|
-
- ext/arel/nodes/random.rb
|
153
|
-
- ext/arel/order_predications.rb
|
154
|
-
- ext/arel/visitors/postgresql.rb
|
155
192
|
- lib/active_record/sort.rb
|
156
193
|
- lib/active_record/sort/version.rb
|
157
194
|
homepage: https://github.com/malomalo/activerecord-sort
|
158
195
|
licenses:
|
159
196
|
- MIT
|
160
197
|
metadata: {}
|
161
|
-
post_install_message:
|
198
|
+
post_install_message:
|
162
199
|
rdoc_options:
|
163
200
|
- "--main"
|
164
201
|
- README.md
|
@@ -171,12 +208,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
171
208
|
version: '0'
|
172
209
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
173
210
|
requirements:
|
174
|
-
- - "
|
211
|
+
- - ">"
|
175
212
|
- !ruby/object:Gem::Version
|
176
|
-
version:
|
213
|
+
version: 1.3.1
|
177
214
|
requirements: []
|
178
|
-
rubygems_version: 3.
|
179
|
-
signing_key:
|
215
|
+
rubygems_version: 3.1.4
|
216
|
+
signing_key:
|
180
217
|
specification_version: 4
|
181
218
|
summary: A safe way to accept user parameters and order against your ActiveRecord
|
182
219
|
Models
|
data/ext/arel/nodes/ascending.rb
DELETED
data/ext/arel/nodes/random.rb
DELETED
@@ -1,28 +0,0 @@
|
|
1
|
-
module Arel
|
2
|
-
module Visitors
|
3
|
-
class PostgreSQL
|
4
|
-
private
|
5
|
-
|
6
|
-
def visit_Arel_Nodes_Ascending o, collector
|
7
|
-
case o.nulls
|
8
|
-
when :nulls_first then visit(o.expr, collector) << ' ASC NULLS FIRST'
|
9
|
-
when :nulls_last then visit(o.expr, collector) << ' ASC NULLS LAST'
|
10
|
-
else visit(o.expr, collector) << ' ASC'
|
11
|
-
end
|
12
|
-
end
|
13
|
-
|
14
|
-
def visit_Arel_Nodes_Descending o, collector
|
15
|
-
case o.nulls
|
16
|
-
when :nulls_first then visit(o.expr, collector) << ' DESC NULLS FIRST'
|
17
|
-
when :nulls_last then visit(o.expr, collector) << ' DESC NULLS LAST'
|
18
|
-
else visit(o.expr, collector) << ' DESC'
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
def visit_Arel_Nodes_RandomOrdering o, collector
|
23
|
-
collector << "RANDOM()"
|
24
|
-
end
|
25
|
-
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end
|