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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7e80869d50f923cf14e1c96774df8fd135320f22
4
- data.tar.gz: c06528fdbba24bc3aac39d2fe9becf5581e1287e
3
+ metadata.gz: c3c0b4769e4ae7659a41f2788aa32a1ebb239606
4
+ data.tar.gz: a52100b3a3766cafc11ab29dfd69a1df6ac58782
5
5
  SHA512:
6
- metadata.gz: e050a3abb028df1dc5f7b4bf407bb17de55e0e5a11621b7e5197a5165a81d1fbb3e4a6e1a641c8dfc971dab8a14c6c368b658f533eace92c18d3165d1f5b40bc
7
- data.tar.gz: 43d7618eef46eb7b1131bf57ca863ef5a3bd52b155f755c66b8e8360e373bc4d43b4b7359195eff8c670fc3d50e93f5b09e79f03cc51cf36161852138879fa60
6
+ metadata.gz: 8d6b439fefd4a3edd738279ef3beadc37afbad575fc24def2fc61cc46429e7c9269c6ae5891ec443ba3eb26369c1e467c699fc38c694eab435ce30207408b8aa
7
+ data.tar.gz: 5f35554de45ab605602b0197b411af52496c57fdb60675436647e9d4b5f45865c3cbd3de68588974618dd5ff9158143d685f7f358841995b2c201d11cc2d5642
@@ -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 self.column_names.include?(column_or_relation.to_s)
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]
@@ -0,0 +1,7 @@
1
+ module Arel
2
+ module Nodes
3
+ class RandomOrdering < Arel::Nodes::Node
4
+
5
+ end
6
+ end
7
+ end
@@ -19,6 +19,10 @@ module Arel
19
19
  end
20
20
  end
21
21
 
22
+ def visit_Arel_Nodes_RandomOrdering o, collector
23
+ collector << "RANDOM()"
24
+ end
25
+
22
26
  end
23
27
  end
24
28
  end
@@ -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
 
@@ -1,5 +1,5 @@
1
1
  module ActiveRecord
2
2
  module Sort
3
- VERSION = '5.0.0'
3
+ VERSION = '5.0.0.1'
4
4
  end
5
5
  end
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: 2016-08-17 00:00:00.000000000 Z
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.18.4
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.18.4
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: '5.0'
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: '5.0'
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.5.1
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