binxtils 0.8.0 → 0.8.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +3 -3
- data/app/controllers/concerns/binxtils/sortable_table.rb +9 -4
- data/lib/binxtils/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: c8b4a35440c2841b1f08baf31395cdf61bed5d1c0ec4ce33cc98a5dab8f43f22
|
|
4
|
+
data.tar.gz: 9da110f74dd61abf3896e6fae12e52ccbabef082338f9cd905ad8b70dad11859
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: a002ee9f7a38fa824cc20a5a0e6c9ecfdb35f55f4b905155b1d05a449e3aec4dc16019bff709b20f9c9224d5c113ffa1723677dbb7b8647a65970182515498d2
|
|
7
|
+
data.tar.gz: f89dbdb5382f6b3e608ac7742d79cd9b935becf19ed554e59b0cf7b2bc34f647d9d33bf0061f0edadcaa44e977f8e8a6a66466c307f32f2d4f8fb64abc1685eb
|
data/README.md
CHANGED
|
@@ -59,12 +59,12 @@ class BikesController < ApplicationController
|
|
|
59
59
|
end
|
|
60
60
|
```
|
|
61
61
|
|
|
62
|
-
Order with `sortable_order`, which applies `sort_direction` and puts nils last
|
|
62
|
+
Order with `sortable_order`, which applies `sort_direction` and puts nils last. Pass the model to order by its `sort_column` — non-null columns skip `NULLS LAST`, since an index can't serve `DESC NULLS LAST`. It also takes an Arel node or SQL string, which are treated as nullable unless you pass `nulls_last:`:
|
|
63
63
|
|
|
64
64
|
```ruby
|
|
65
|
-
Bike.order(sortable_order)
|
|
65
|
+
Bike.order(sortable_order(Bike))
|
|
66
66
|
Bike.order(sortable_order(Bike.arel_table[sort_column].lower))
|
|
67
|
-
Bike.order(sortable_order("COALESCE((data -> 'bike_count')::integer, 0)"))
|
|
67
|
+
Bike.order(sortable_order("COALESCE((data -> 'bike_count')::integer, 0)", nulls_last: false))
|
|
68
68
|
```
|
|
69
69
|
|
|
70
70
|
## npm package
|
|
@@ -18,10 +18,15 @@ module Binxtils
|
|
|
18
18
|
%w[asc desc].include?(params[:direction]) ? params[:direction] : default_direction
|
|
19
19
|
end
|
|
20
20
|
|
|
21
|
-
# Desc puts nils last, matching asc
|
|
22
|
-
def sortable_order(expression = sort_column)
|
|
23
|
-
node = expression.
|
|
24
|
-
|
|
21
|
+
# Desc puts nils last, matching asc; not for a model's non-null column, since an index can't serve DESC NULLS LAST
|
|
22
|
+
def sortable_order(expression = sort_column, nulls_last: !expression.is_a?(Class) || expression.columns_hash[sort_column]&.null != false)
|
|
23
|
+
node = if expression.is_a?(Class)
|
|
24
|
+
expression.arel_table[sort_column]
|
|
25
|
+
else
|
|
26
|
+
expression.respond_to?(:asc) ? expression : Arel.sql(expression)
|
|
27
|
+
end
|
|
28
|
+
ordering = node.public_send(sort_direction)
|
|
29
|
+
nulls_last ? ordering.nulls_last : ordering
|
|
25
30
|
end
|
|
26
31
|
|
|
27
32
|
def permitted_time_range_columns
|
data/lib/binxtils/version.rb
CHANGED