activeset 0.8.5 → 0.8.6
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/.rubocop.yml +1 -1
- data/CHANGELOG +7 -0
- data/Gemfile.lock +1 -1
- data/activeset.gemspec +1 -1
- data/lib/active_set/filtering/active_record_strategy.rb +5 -3
- data/lib/active_set/sorting/active_record_strategy.rb +6 -2
- data/lib/active_set/sorting/enumerable_strategy.rb +3 -5
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: b5476ab3f9de94a85dc7b5a891d1bef17a39ecd8
|
|
4
|
+
data.tar.gz: e17b933d743291d3c0eaa5aaae990dc056b47b84
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: efae3f352fc6e1038583adb2aea3bbcb45963f972290c13d0f2a67d80db5209a9cab2eb7e80dc4bf8611f35bb4de8005eb5843cb97fdb363aa6fcc48b937f333
|
|
7
|
+
data.tar.gz: f484dc6b89b189e8dfcae29d71429639966b2e7836108c34d4dd58d7f4aa8b4d9f6fdd6915eb806f0a9d317b0bbac2cdcf1a65bca0bcf9c4cd12e3a14ee17a08
|
data/.rubocop.yml
CHANGED
data/CHANGELOG
CHANGED
|
@@ -1,3 +1,10 @@
|
|
|
1
|
+
v 0.8.6
|
|
2
|
+
- fix a bug where ActiveRecord sorting didn't treat NULL values in the same way as Enumerable sorting
|
|
3
|
+
+ where NULL values are sorted as if larger than any non-null value
|
|
4
|
+
- fix a bug with ActiveRecord scope filtering
|
|
5
|
+
+ if we try to use a class method scope that returns something other than an ActiveRecord::Relation
|
|
6
|
+
- update the scopes filtering specs to be more generalized and exhaustive
|
|
7
|
+
- clean up specs in general
|
|
1
8
|
v 0.8.5
|
|
2
9
|
- fix a bug in Enumerable class method filtering when method returns object, not array
|
|
3
10
|
- add specs for Enumerable filtering
|
data/Gemfile.lock
CHANGED
data/activeset.gemspec
CHANGED
|
@@ -6,7 +6,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
|
6
6
|
Gem::Specification.new do |spec|
|
|
7
7
|
spec.platform = Gem::Platform::RUBY
|
|
8
8
|
spec.name = 'activeset'
|
|
9
|
-
spec.version = '0.8.
|
|
9
|
+
spec.version = '0.8.6'
|
|
10
10
|
spec.authors = ['Stephen Margheim']
|
|
11
11
|
spec.email = ['stephen.margheim@gmail.com']
|
|
12
12
|
|
|
@@ -14,13 +14,15 @@ class ActiveSet
|
|
|
14
14
|
if execute_where_operation?
|
|
15
15
|
statement = where_operation
|
|
16
16
|
elsif execute_merge_operation?
|
|
17
|
-
|
|
17
|
+
begin
|
|
18
|
+
statement = merge_operation
|
|
19
|
+
rescue ArgumentError # thrown if merging a non-ActiveRecord::Relation
|
|
20
|
+
return false
|
|
21
|
+
end
|
|
18
22
|
else
|
|
19
23
|
return false
|
|
20
24
|
end
|
|
21
25
|
|
|
22
|
-
return false if throws?(ActiveRecord::StatementInvalid) { statement.load }
|
|
23
|
-
|
|
24
26
|
statement
|
|
25
27
|
end
|
|
26
28
|
|
|
@@ -41,15 +41,19 @@ class ActiveSet
|
|
|
41
41
|
@set.eager_load(associations_hash)
|
|
42
42
|
end
|
|
43
43
|
|
|
44
|
+
# https://stackoverflow.com/a/44912964/2884386
|
|
45
|
+
# Force null values to be sorted as if larger than any non-null value
|
|
46
|
+
# ASC => [-2, -1, 1, 2, nil]
|
|
47
|
+
# DESC => [nil, 2, 1, -1, -2]
|
|
44
48
|
def order_operation_for(attribute_instruction)
|
|
45
49
|
attribute_model = attribute_model_for(attribute_instruction)
|
|
46
50
|
|
|
47
51
|
arel_column = Arel::Table.new(attribute_model.table_name)[attribute_instruction.attribute]
|
|
48
52
|
arel_column = case_insensitive?(attribute_instruction) ? arel_column.lower : arel_column
|
|
49
|
-
|
|
50
53
|
arel_direction = direction_operator(attribute_instruction.value)
|
|
54
|
+
nil_sorter = arel_column.send(arel_direction == :asc ? :eq : :not_eq, nil)
|
|
51
55
|
|
|
52
|
-
attribute_model.order(arel_column.send(arel_direction))
|
|
56
|
+
attribute_model.order(nil_sorter).order(arel_column.send(arel_direction))
|
|
53
57
|
end
|
|
54
58
|
|
|
55
59
|
def attribute_model_for(attribute_instruction)
|
|
@@ -17,11 +17,9 @@ class ActiveSet
|
|
|
17
17
|
value_for_comparison = sortable_numeric_for(instruction, item)
|
|
18
18
|
direction_multiplier = direction_multiplier(instruction.value)
|
|
19
19
|
|
|
20
|
-
#
|
|
21
|
-
#
|
|
22
|
-
#
|
|
23
|
-
# element, and wrapping nil values with either 1 or -1 as the first
|
|
24
|
-
# element
|
|
20
|
+
# Force null values to be sorted as if larger than any non-null value
|
|
21
|
+
# ASC => [-2, -1, 1, 2, nil]
|
|
22
|
+
# DESC => [nil, 2, 1, -1, -2]
|
|
25
23
|
if value_for_comparison.nil?
|
|
26
24
|
[direction_multiplier, 0]
|
|
27
25
|
else
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: activeset
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.8.
|
|
4
|
+
version: 0.8.6
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Stephen Margheim
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: exe
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2019-05-
|
|
11
|
+
date: 2019-05-05 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: activesupport
|