activerecord-sort 5.1.0 → 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
- SHA1:
3
- metadata.gz: 84044f4d2e6143480042232241610d5b0f6338b1
4
- data.tar.gz: 6738849627c56faa780dcc7a6e0a740134580727
2
+ SHA256:
3
+ metadata.gz: 1845764483eacf7b3cce0ee2b9b7f3d1cff6d3d1211518f12e54be59a7cccf9f
4
+ data.tar.gz: d4072a886aaeed64c12d01a5ede815db50efe30823731c0e8fb6c0c69fd8e762
5
5
  SHA512:
6
- metadata.gz: e9fbde3f1d62240bfb453190b7f1195926873380347752e52ebc1740032f64f909a257e2ba5175ae619d2e1411091f53c4c418b48104ff59413a14210a2a12c2
7
- data.tar.gz: 18647e51b72fff49310ffb6ac9a389522a840cb846bb547595eb5c0b93e9c66f19ff8f23eea714c9bf2d0b1673e0aa9d1561f14d4d8f7b6eeacfe470c92470f8
6
+ metadata.gz: 4356863599576c5a49c4a720eb6fd1be043235532d606cde9a1592d562ea643d1fe1abe906dcdc6c5fa6ef65155917605904ec780fdabb24858e0171364e4971
7
+ data.tar.gz: 104bdf59db87f9781f002af1faf40834373fa07fda6887f666f5d9324c25ee74b31f48b4f3d4ba2819d2f259907a89eede04f3e3ce61f8ebd7db0e234d050b78
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # ActiveRecord::sort
1
+ # ActiveRecord::sort [![Travis CI](https://travis-ci.org/malomalo/activerecord-sort.svg?branch=master)](https://travis-ci.org/malomalo/activerecord-sort)
2
2
 
3
3
  `ActiveRecord::sort` provides and easy way to accept user input and order a query by the input.
4
4
 
@@ -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)
@@ -43,9 +43,9 @@ module ActiveRecord
43
43
  self.order(Arel::Nodes::RandomOrdering.new)
44
44
  end
45
45
 
46
+ # TODO: probably don't need to cast to sym
46
47
  def sort_for_column(column, options)
47
- column = self.arel_table[column.to_s.underscore]
48
- direction = (options.is_a?(Hash) ? 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)
49
49
 
50
50
  nulls = (options.is_a?(Hash) ? options.values.first.to_sym : nil)
51
51
  if direction == :desc
@@ -67,7 +67,7 @@ module ActiveRecord
67
67
  options.each do |order|
68
68
  order = Array(order)
69
69
  order.each do |column, options|
70
- column = relation.klass.arel_table[column]
70
+ column = Arel::Attributes::Relation.new(relation.klass.arel_table[column], relation.name)
71
71
  direction = (options.is_a?(Hash) ? options.keys.first.to_sym : options.to_s.downcase.to_sym)
72
72
 
73
73
  nulls = (options.is_a?(Hash) ? options.values.first.to_sym : nil)
@@ -110,7 +110,7 @@ module ActiveRecord
110
110
  order = Arel::Nodes::Descending.new(column, nulls)
111
111
  end
112
112
 
113
- resource = resource.joins(relation.name)
113
+ resource = resource.left_outer_joins(relation.name)
114
114
  resource = resource.order(order)
115
115
  end
116
116
  end
@@ -120,4 +120,4 @@ module ActiveRecord
120
120
  end
121
121
 
122
122
  end
123
- 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 = '5.1.0'
3
+ VERSION = '6.1.0.rc1'
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,29 +1,43 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: activerecord-sort
3
3
  version: !ruby/object:Gem::Version
4
- version: 5.1.0
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: 2017-08-28 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
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: 6.1.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: 6.1.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: arel-extensions
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
18
32
  - !ruby/object:Gem::Version
19
- version: 5.1.0
33
+ version: 6.1.0.rc2
20
34
  type: :runtime
21
35
  prerelease: false
22
36
  version_requirements: !ruby/object:Gem::Requirement
23
37
  requirements:
24
- - - "~>"
38
+ - - ">="
25
39
  - !ruby/object:Gem::Version
26
- version: 5.1.0
40
+ version: 6.1.0.rc2
27
41
  - !ruby/object:Gem::Dependency
28
42
  name: pg
29
43
  requirement: !ruby/object:Gem::Requirement
@@ -109,7 +123,7 @@ dependencies:
109
123
  - !ruby/object:Gem::Version
110
124
  version: '0'
111
125
  - !ruby/object:Gem::Dependency
112
- name: factory_girl
126
+ name: factory_bot
113
127
  requirement: !ruby/object:Gem::Requirement
114
128
  requirements:
115
129
  - - ">="
@@ -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,13 +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
- rubyforge_project:
179
- rubygems_version: 2.6.11
180
- signing_key:
215
+ rubygems_version: 3.1.4
216
+ signing_key:
181
217
  specification_version: 4
182
218
  summary: A safe way to accept user parameters and order against your ActiveRecord
183
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