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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: cff1abfec5ff89217d35624be89876e6f88943250f3da263d39caf520fa20b9b
4
- data.tar.gz: 7ce1af43d5e20dea32de13d1b542b6efa6f43b6a94a18bfabffb319740fedba4
3
+ metadata.gz: 1845764483eacf7b3cce0ee2b9b7f3d1cff6d3d1211518f12e54be59a7cccf9f
4
+ data.tar.gz: d4072a886aaeed64c12d01a5ede815db50efe30823731c0e8fb6c0c69fd8e762
5
5
  SHA512:
6
- metadata.gz: 8ef79654a460ec5c1a7f134aa3faba1c49793a51bbc93909b928e56c23b9157393a9f7e328318301069f75d2fa36c00999d87e400544db76a37c8a2a5efb134f
7
- data.tar.gz: e78df6d8a039c2036c054d44eb422388847aea6a0bd34022d6964a70c0c8de38cb43d69100892416e81b43e4fcc099b6b4a8cb0494baafd35d322748ebb2e312
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.order(:id).to_sql
16
+ Property.sort(:id).to_sql
17
17
  # => "...ORDER BY properties.id ASC"
18
18
 
19
- Property.order(:id, :name).to_sql
19
+ Property.sort(:id, :name).to_sql
20
20
  # => "...ORDER BY properties.id ASC, properties.name ASC"
21
21
 
22
- Property.order(:id => :desc).to_sql
22
+ Property.sort(id: :desc).to_sql
23
23
  # => "...ORDER BY properties.id DESC"
24
24
 
25
- Property.order(:id => {:asc => :nulls_first})
25
+ Property.sort(id: {asc: :nulls_first})
26
26
  # => "...ORDER BY properties.id ASC NULLS FIRST"
27
27
 
28
- Property.order(:id => {:asc => :nulls_last})
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.order(:addresses => :id).to_sql
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.order(:addresses => {:id => :desc}).to_sql
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.order(:addresses => {:id => {:asc => :nulls_frist}}).to_sql
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
  ```
@@ -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
- column = self.arel_table[column.to_s.underscore]
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.joins(relation.name)
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
@@ -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
@@ -1,5 +1,5 @@
1
1
  module ActiveRecord
2
2
  module Sort
3
- VERSION = '6.0.0.2'
3
+ VERSION = '6.1.0.rc1'
4
4
  end
5
5
  end
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.0.0.2
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: 2019-08-22 00:00:00.000000000 Z
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.0.0
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.0.0
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: '0'
213
+ version: 1.3.1
177
214
  requirements: []
178
- rubygems_version: 3.0.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
@@ -1,14 +0,0 @@
1
- module Arel
2
- module Nodes
3
- class Ascending < Ordering
4
-
5
- attr_accessor :nulls
6
-
7
- def initialize expr, nulls=nil
8
- super(expr)
9
- @nulls = nulls
10
- end
11
-
12
- end
13
- end
14
- end
@@ -1,15 +0,0 @@
1
- module Arel
2
- module Nodes
3
- class Descending < Ordering
4
-
5
- attr_accessor :nulls
6
-
7
- def initialize expr, nulls=nil
8
- super(expr)
9
- @nulls = nulls
10
- end
11
-
12
- end
13
-
14
- end
15
- end
@@ -1,7 +0,0 @@
1
- module Arel
2
- module Nodes
3
- class RandomOrdering < Arel::Nodes::Node
4
-
5
- end
6
- end
7
- end
@@ -1,14 +0,0 @@
1
- # Ordering with :nulls_last, :nulls_first options
2
- module Arel
3
- module OrderPredications
4
-
5
- def asc(nulls=nil)
6
- Nodes::Ascending.new self, nulls
7
- end
8
-
9
- def desc(nulls=nil)
10
- Nodes::Descending.new self, nulls
11
- end
12
-
13
- end
14
- end
@@ -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