activerecord-sort 5.0.0 → 5.0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/ext/active_record/base.rb +8 -1
- data/ext/arel/nodes/random.rb +7 -0
- data/ext/arel/visitors/postgresql.rb +4 -0
- data/lib/active_record/sort.rb +1 -0
- data/lib/active_record/sort/version.rb +1 -1
- metadata +8 -19
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c3c0b4769e4ae7659a41f2788aa32a1ebb239606
|
4
|
+
data.tar.gz: a52100b3a3766cafc11ab29dfd69a1df6ac58782
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8d6b439fefd4a3edd738279ef3beadc37afbad575fc24def2fc61cc46429e7c9269c6ae5891ec443ba3eb26369c1e467c699fc38c694eab435ce30207408b8aa
|
7
|
+
data.tar.gz: 5f35554de45ab605602b0197b411af52496c57fdb60675436647e9d4b5f45865c3cbd3de68588974618dd5ff9158143d685f7f358841995b2c201d11cc2d5642
|
data/ext/active_record/base.rb
CHANGED
@@ -12,6 +12,7 @@ module ActiveRecord
|
|
12
12
|
# :id => {:desc => :nulls_last}
|
13
13
|
# :listings => :id
|
14
14
|
# :listings => {:id => {:asc => :nulls_first}}
|
15
|
+
# :random
|
15
16
|
def sort(*ordering)
|
16
17
|
resource = all
|
17
18
|
ordering.compact!
|
@@ -22,7 +23,9 @@ module ActiveRecord
|
|
22
23
|
order = Array(order)
|
23
24
|
|
24
25
|
order.each do |column_or_relation, options|
|
25
|
-
if
|
26
|
+
if column_or_relation.to_sym == :random
|
27
|
+
resource = resource.random_sort
|
28
|
+
elsif self.column_names.include?(column_or_relation.to_s)
|
26
29
|
resource = resource.sort_for_column(column_or_relation, options)
|
27
30
|
elsif reflect_on_association(column_or_relation.to_sym)
|
28
31
|
resource = resource.select(resource.klass.arel_table[Arel::Nodes::SqlLiteral.new('*')])
|
@@ -35,6 +38,10 @@ module ActiveRecord
|
|
35
38
|
|
36
39
|
resource
|
37
40
|
end
|
41
|
+
|
42
|
+
def random_sort
|
43
|
+
self.order(Arel::Nodes::RandomOrdering.new)
|
44
|
+
end
|
38
45
|
|
39
46
|
def sort_for_column(column, options)
|
40
47
|
column = self.arel_table[column.to_s.underscore]
|
data/lib/active_record/sort.rb
CHANGED
@@ -3,6 +3,7 @@ require 'active_record'
|
|
3
3
|
require File.expand_path(File.join(__FILE__, '../../../ext/arel/order_predications'))
|
4
4
|
require File.expand_path(File.join(__FILE__, '../../../ext/arel/nodes/ascending'))
|
5
5
|
require File.expand_path(File.join(__FILE__, '../../../ext/arel/nodes/descending'))
|
6
|
+
require File.expand_path(File.join(__FILE__, '../../../ext/arel/nodes/random'))
|
6
7
|
require File.expand_path(File.join(__FILE__, '../../../ext/arel/visitors/postgresql'))
|
7
8
|
require File.expand_path(File.join(__FILE__, '../../../ext/active_record/base'))
|
8
9
|
|
metadata
CHANGED
@@ -1,55 +1,43 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: activerecord-sort
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 5.0.0
|
4
|
+
version: 5.0.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jon Bracy
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2017-02-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: pg
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "~>"
|
18
|
-
- !ruby/object:Gem::Version
|
19
|
-
version: '0.18'
|
20
17
|
- - ">="
|
21
18
|
- !ruby/object:Gem::Version
|
22
|
-
version: 0
|
19
|
+
version: '0'
|
23
20
|
type: :runtime
|
24
21
|
prerelease: false
|
25
22
|
version_requirements: !ruby/object:Gem::Requirement
|
26
23
|
requirements:
|
27
|
-
- - "~>"
|
28
|
-
- !ruby/object:Gem::Version
|
29
|
-
version: '0.18'
|
30
24
|
- - ">="
|
31
25
|
- !ruby/object:Gem::Version
|
32
|
-
version: 0
|
26
|
+
version: '0'
|
33
27
|
- !ruby/object:Gem::Dependency
|
34
28
|
name: activerecord
|
35
29
|
requirement: !ruby/object:Gem::Requirement
|
36
30
|
requirements:
|
37
31
|
- - "~>"
|
38
32
|
- !ruby/object:Gem::Version
|
39
|
-
version:
|
40
|
-
- - ">="
|
41
|
-
- !ruby/object:Gem::Version
|
42
|
-
version: 5.0.0
|
33
|
+
version: 5.0.0.rc1
|
43
34
|
type: :runtime
|
44
35
|
prerelease: false
|
45
36
|
version_requirements: !ruby/object:Gem::Requirement
|
46
37
|
requirements:
|
47
38
|
- - "~>"
|
48
39
|
- !ruby/object:Gem::Version
|
49
|
-
version:
|
50
|
-
- - ">="
|
51
|
-
- !ruby/object:Gem::Version
|
52
|
-
version: 5.0.0
|
40
|
+
version: 5.0.0.rc1
|
53
41
|
- !ruby/object:Gem::Dependency
|
54
42
|
name: bundler
|
55
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -161,6 +149,7 @@ files:
|
|
161
149
|
- ext/active_record/base.rb
|
162
150
|
- ext/arel/nodes/ascending.rb
|
163
151
|
- ext/arel/nodes/descending.rb
|
152
|
+
- ext/arel/nodes/random.rb
|
164
153
|
- ext/arel/order_predications.rb
|
165
154
|
- ext/arel/visitors/postgresql.rb
|
166
155
|
- lib/active_record/sort.rb
|
@@ -187,7 +176,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
187
176
|
version: '0'
|
188
177
|
requirements: []
|
189
178
|
rubyforge_project:
|
190
|
-
rubygems_version: 2.
|
179
|
+
rubygems_version: 2.6.8
|
191
180
|
signing_key:
|
192
181
|
specification_version: 4
|
193
182
|
summary: A safe way to accept user parameters and order against your ActiveRecord
|