miscellany 0.1.22 → 0.1.24
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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6de3e8ac55956c58bff00af5ffae6ce8972b142be6a5aad47096c4776658ba4e
|
4
|
+
data.tar.gz: 4668195d6a891348e495fff7ecf187415eef6f2588d14e33be556f04f7358042
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2cec7d17686d2d9faf88dcfc20ac2ca5fba8f10ca7c1e021a7e0b67af4f6506b8d0a03444437ac1aae23eaa39e3a116cbb9e9ef62b649ec73faaf3b45e155772
|
7
|
+
data.tar.gz: 7a0c8b98668ad66aebd4b51e3d41aa969a13e3138992021f36bf95f04be3e1db289f95fb43e95f04e8b8876c2f5e4652a9e1609b1dfbd907595f21f7d9513d4d
|
@@ -203,12 +203,12 @@ module Miscellany
|
|
203
203
|
|
204
204
|
base_module ||= mod
|
205
205
|
|
206
|
-
if mod.name.
|
206
|
+
if mod.name.end_with? "Patch"
|
207
207
|
base_full_name = base_module.to_s
|
208
208
|
mod_full_name = mod.to_s
|
209
209
|
mod_rel_name = mod_full_name.sub(base_full_name, '')
|
210
210
|
mod_rel_bits = mod_rel_name.split('::').select(&:present?).map do |bit|
|
211
|
-
bit.
|
211
|
+
bit.end_with?('Patch') ? bit[0..-6] : bit
|
212
212
|
end
|
213
213
|
final_mod_name = [install_base, *mod_rel_bits].select(&:present?).join("::")
|
214
214
|
install_mod = final_mod_name.constantize
|
@@ -202,6 +202,18 @@ module Miscellany
|
|
202
202
|
limit -= offset unless limit.nil?
|
203
203
|
|
204
204
|
query = items
|
205
|
+
|
206
|
+
applied_sorts.each do |sort|
|
207
|
+
# TODO Throw an error if joins: is present on a non-AR::Relation?
|
208
|
+
if sort[:joins].is_a?(ActiveRecord::Relation)
|
209
|
+
query = query.merge(sort[:joins])
|
210
|
+
elsif sort[:joins].is_a?(Proc)
|
211
|
+
query = sort[:joins].call(query)
|
212
|
+
elsif sort[:joins].present?
|
213
|
+
query = query.joins(sort[:joins])
|
214
|
+
end
|
215
|
+
end
|
216
|
+
|
205
217
|
sort_clause = sort_sql
|
206
218
|
query = query.order(Arel.sql(sort_clause)) if sort_clause.present?
|
207
219
|
|
@@ -219,13 +231,19 @@ module Miscellany
|
|
219
231
|
[slice_start, slice_end == -1 ? nil : slice_end]
|
220
232
|
end
|
221
233
|
|
222
|
-
def
|
223
|
-
|
224
|
-
|
234
|
+
def applied_sorts
|
235
|
+
@applied_sorts ||= begin
|
236
|
+
sorts = [ *Array(self.sort), *options[:sort_parser]&.default_sorts]
|
237
|
+
sorts.compact!
|
238
|
+
sorts = Miscellany::SortLang.distinct_sorts(sorts)
|
239
|
+
sorts
|
240
|
+
end
|
241
|
+
end
|
225
242
|
|
226
|
-
|
243
|
+
def sort_sql
|
244
|
+
return nil unless applied_sorts.present?
|
227
245
|
|
228
|
-
Miscellany::SortLang.sqlize(
|
246
|
+
Miscellany::SortLang.sqlize(applied_sorts)
|
229
247
|
end
|
230
248
|
end
|
231
249
|
end
|
data/lib/miscellany/sort_lang.rb
CHANGED
@@ -22,11 +22,11 @@ module Miscellany
|
|
22
22
|
sort.compact
|
23
23
|
end
|
24
24
|
|
25
|
-
def self.
|
25
|
+
def self.distinct_sorts(sorts)
|
26
26
|
seen_sorts = Set.new
|
27
27
|
|
28
28
|
# Only include each sort key/"column" once
|
29
|
-
sorts
|
29
|
+
sorts.select do |sort|
|
30
30
|
sid = sort[:key] || sort[:column]
|
31
31
|
next true unless sid.present?
|
32
32
|
|
@@ -37,7 +37,9 @@ module Miscellany
|
|
37
37
|
true
|
38
38
|
end
|
39
39
|
end
|
40
|
+
end
|
40
41
|
|
42
|
+
def self.sqlize(sorts)
|
41
43
|
sorts.map do |sort|
|
42
44
|
order = sort[:order] || 'ASC'
|
43
45
|
if sort[:column].is_a?(Proc)
|
data/lib/miscellany/version.rb
CHANGED
@@ -30,14 +30,17 @@ describe Miscellany::SortLang do
|
|
30
30
|
end
|
31
31
|
end
|
32
32
|
|
33
|
-
describe ".
|
33
|
+
describe ".distinct_sorts" do
|
34
34
|
it "only includes each sort key once" do
|
35
|
-
|
35
|
+
distinct = Miscellany::SortLang.distinct_sorts([
|
36
36
|
{ column: "created_at", order: "ASC" },
|
37
37
|
{ column: "created_at", order: "DESC" },
|
38
|
-
])
|
38
|
+
])
|
39
|
+
expect(Miscellany::SortLang.sqlize(distinct)).to eql "created_at ASC NULLS FIRST"
|
39
40
|
end
|
41
|
+
end
|
40
42
|
|
43
|
+
describe ".sqlize" do
|
41
44
|
describe "nulls: option" do
|
42
45
|
it "accepts a nulls: option" do
|
43
46
|
expect(Miscellany::SortLang.sqlize([
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: miscellany
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.24
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ethan Knapp
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2024-08-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|