activerecord-sort 6.1.0.rc1 → 6.1.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
  SHA256:
3
- metadata.gz: 1845764483eacf7b3cce0ee2b9b7f3d1cff6d3d1211518f12e54be59a7cccf9f
4
- data.tar.gz: d4072a886aaeed64c12d01a5ede815db50efe30823731c0e8fb6c0c69fd8e762
3
+ metadata.gz: 24b933e7b9456dfe06da3a8da7a20ad8bf7b03043c81667021dbdafc8f6b9cf4
4
+ data.tar.gz: 77347b9a5f294de607d485598b2c41305e66b2932debec47da84ded5cca9772d
5
5
  SHA512:
6
- metadata.gz: 4356863599576c5a49c4a720eb6fd1be043235532d606cde9a1592d562ea643d1fe1abe906dcdc6c5fa6ef65155917605904ec780fdabb24858e0171364e4971
7
- data.tar.gz: 104bdf59db87f9781f002af1faf40834373fa07fda6887f666f5d9324c25ee74b31f48b4f3d4ba2819d2f259907a89eede04f3e3ce61f8ebd7db0e234d050b78
6
+ metadata.gz: 41524ce760cfbf7f8bdb93bd5688c149e553a277b615d45c240939d8c51541c6d34660ccf8ad681ce78aeececcf86995b62ab20fd10797f5440115b88767acd6
7
+ data.tar.gz: f2098644c9201456b82899f1b621f8348a140bee47d6db7e4780ca4273b2ee47061771c535905d727a70195d4b20fc3da2c02181396bfcf84c1e645a739ef73c
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Jon Bracy
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
22
+
data/README.md CHANGED
@@ -1,16 +1,27 @@
1
- # ActiveRecord::sort [![Travis CI](https://travis-ci.org/malomalo/activerecord-sort.svg?branch=master)](https://travis-ci.org/malomalo/activerecord-sort)
1
+ # ActiveRecord::Sort
2
2
 
3
- `ActiveRecord::sort` provides and easy way to accept user input and order a query by the input.
3
+ `ActiveRecord::Sort` provides and easy way to accept user input and order a query by the input.
4
4
 
5
- Installtion
6
- -----------
5
+ Installation
6
+ ------------
7
7
 
8
- - Add `gem 'activerecord-sort', require: 'active_record/sort'
9
- - Run `bundle install`
8
+ Add `sunstone` to your Gemfile and run `bundle`:
9
+
10
+ ```ruby
11
+ gem 'activerecord-sort', require: 'active_record/sort'
12
+ ```
13
+
14
+ Or install the gem and require it:
15
+
16
+ ```sh
17
+ gem install activerecord-sort
18
+ irb
19
+ # => require('active_record/sort')
20
+ ```
10
21
 
11
22
  Examples
12
23
  --------
13
- `ActiveRecord::sort` supports the following cases:
24
+ `ActiveRecord::Sort` supports the following cases:
14
25
 
15
26
  ```ruby
16
27
  Property.sort(:id).to_sql
@@ -1,5 +1,5 @@
1
1
  module ActiveRecord
2
2
  module Sort
3
- VERSION = '6.1.0.rc1'
3
+ VERSION = '6.1.0.1'
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.1.0.rc1
4
+ version: 6.1.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: 2020-12-29 00:00:00.000000000 Z
11
+ date: 2021-03-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -30,14 +30,14 @@ dependencies:
30
30
  requirements:
31
31
  - - ">="
32
32
  - !ruby/object:Gem::Version
33
- version: 6.1.0.rc2
33
+ version: 6.1.0
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - ">="
39
39
  - !ruby/object:Gem::Version
40
- version: 6.1.0.rc2
40
+ version: 6.1.0
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: pg
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -156,14 +156,14 @@ dependencies:
156
156
  requirements:
157
157
  - - ">="
158
158
  - !ruby/object:Gem::Version
159
- version: 6.1.0.rc1
159
+ version: 6.1.0.2
160
160
  type: :development
161
161
  prerelease: false
162
162
  version_requirements: !ruby/object:Gem::Requirement
163
163
  requirements:
164
164
  - - ">="
165
165
  - !ruby/object:Gem::Version
166
- version: 6.1.0.rc1
166
+ version: 6.1.0.2
167
167
  - !ruby/object:Gem::Dependency
168
168
  name: webmock
169
169
  requirement: !ruby/object:Gem::Requirement
@@ -187,8 +187,8 @@ extensions: []
187
187
  extra_rdoc_files:
188
188
  - README.md
189
189
  files:
190
+ - LICENSE
190
191
  - README.md
191
- - ext/active_record/base.rb
192
192
  - lib/active_record/sort.rb
193
193
  - lib/active_record/sort/version.rb
194
194
  homepage: https://github.com/malomalo/activerecord-sort
@@ -208,11 +208,11 @@ required_ruby_version: !ruby/object:Gem::Requirement
208
208
  version: '0'
209
209
  required_rubygems_version: !ruby/object:Gem::Requirement
210
210
  requirements:
211
- - - ">"
211
+ - - ">="
212
212
  - !ruby/object:Gem::Version
213
- version: 1.3.1
213
+ version: '0'
214
214
  requirements: []
215
- rubygems_version: 3.1.4
215
+ rubygems_version: 3.2.3
216
216
  signing_key:
217
217
  specification_version: 4
218
218
  summary: A safe way to accept user parameters and order against your ActiveRecord
@@ -1,123 +0,0 @@
1
- require 'active_record'
2
- require 'active_record/relation'
3
-
4
- module ActiveRecord
5
- module QueryMethods
6
- # class << self
7
-
8
- # ordering:
9
- # :id
10
- # :name, :id
11
- # :id => :desc
12
- # :id => {:desc => :nulls_last}
13
- # :listings => :id
14
- # :listings => {:id => {:asc => :nulls_first}}
15
- # :random
16
- def sort(*ordering)
17
- resource = all
18
- ordering.compact!
19
- ordering.flatten!
20
- return resource if ordering.size == 0
21
-
22
- ordering.each do |order|
23
- order = Array(order)
24
-
25
- order.each do |column_or_relation, options|
26
- if column_or_relation.to_sym == :random
27
- resource = resource.random_sort
28
- elsif self.column_names.include?(column_or_relation.to_s)
29
- resource = resource.sort_for_column(self.arel_table[column_or_relation.to_s], options)
30
- elsif reflect_on_association(column_or_relation.to_sym)
31
- resource = resource.select(resource.klass.arel_table[Arel::Nodes::SqlLiteral.new('*')])
32
- resource = resource.sort_for_relation(column_or_relation.to_sym, options)
33
- else
34
- raise ActiveRecord::StatementInvalid.new("Unkown column #{column_or_relation}")
35
- end
36
- end
37
- end
38
-
39
- resource
40
- end
41
-
42
- def random_sort
43
- self.order(Arel::Nodes::RandomOrdering.new)
44
- end
45
-
46
- # TODO: probably don't need to cast to sym
47
- def sort_for_column(column, options)
48
- direction = (options.is_a?(Hash) || options.class.name == "ActionController::Parameters" ? options.keys.first.to_sym : options.to_s.downcase.to_sym)
49
-
50
- nulls = (options.is_a?(Hash) ? options.values.first.to_sym : nil)
51
- if direction == :desc
52
- self.order(Arel::Nodes::Descending.new(column, nulls))
53
- elsif direction == :asc || direction == :''
54
- self.order(Arel::Nodes::Ascending.new(column, nulls))
55
- else
56
- raise ActiveRecord::StatementInvalid.new("Unkown ordering #{direction}")
57
- end
58
- end
59
-
60
- def sort_for_relation(relation, options)
61
- resource = self
62
- relation = reflect_on_association(relation)
63
-
64
- if relation.macro == :has_many
65
- options = [options] if !options.is_a?(Array)
66
-
67
- options.each do |order|
68
- order = Array(order)
69
- order.each do |column, options|
70
- column = Arel::Attributes::Relation.new(relation.klass.arel_table[column], relation.name)
71
- direction = (options.is_a?(Hash) ? options.keys.first.to_sym : options.to_s.downcase.to_sym)
72
-
73
- nulls = (options.is_a?(Hash) ? options.values.first.to_sym : nil)
74
- if direction == :desc
75
- # aggregation = Arel::Nodes::Max.new([column], "max_#{relation.name}_#{column.name}")
76
- # order = Arel::Nodes::Descending.new(Arel::Nodes::SqlLiteral.new("max_#{relation.name}_#{column.name}"), nulls)
77
-
78
- if relation.options[:through]
79
- resource = resource.joins(relation.options[:through] => relation.source_reflection_name)
80
- else
81
- resource = resource.joins(relation.name)
82
- end
83
- # resource = resource.select(aggregation)
84
- # resource = resource.order(order)
85
- resource = resource.order(Arel::Nodes::Descending.new(column, nulls))
86
- else
87
- # aggregation = Arel::Nodes::Min.new([column], "min_#{relation.name}_#{column.name}")
88
- order = Arel::Nodes::Ascending.new(Arel::Nodes::SqlLiteral.new("min_#{relation.name}_#{column.name}"), nulls)
89
-
90
- resource = resource.joins(relation.name)
91
- # resource = resource.select(aggregation)
92
- # resource = resource.order(order)
93
- resource = resource.order(Arel::Nodes::Ascending.new(column, nulls))
94
- end
95
- end
96
- end
97
- elsif relation.macro == :belongs_to || relation.macro == :has_one
98
- options = [options] if !options.is_a?(Array)
99
-
100
- options.each do |order|
101
- order = Array(order)
102
- order.each do |column, options|
103
- column = relation.klass.arel_table[column]
104
- direction = (options.is_a?(Hash) ? options.keys.first.to_sym : options.to_s.downcase.to_sym)
105
-
106
- nulls = (options.is_a?(Hash) ? options.values.first.to_sym : nil)
107
- if direction == :asc
108
- order = Arel::Nodes::Ascending.new(column, nulls)
109
- else
110
- order = Arel::Nodes::Descending.new(column, nulls)
111
- end
112
-
113
- resource = resource.left_outer_joins(relation.name)
114
- resource = resource.order(order)
115
- end
116
- end
117
- end
118
-
119
- resource
120
- end
121
-
122
- end
123
- end