activeset 0.8.5 → 0.8.6

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
  SHA1:
3
- metadata.gz: 54b59c64a9123a20e6c545a47465ad67fb32ab50
4
- data.tar.gz: 047caa653858d885ccc875590374989e9a29463c
3
+ metadata.gz: b5476ab3f9de94a85dc7b5a891d1bef17a39ecd8
4
+ data.tar.gz: e17b933d743291d3c0eaa5aaae990dc056b47b84
5
5
  SHA512:
6
- metadata.gz: ba97bcac5e9a3e8e08cfddb65cf366773229358a7a4e8c5821d20ae1a55e9af620c01c8ecd860e978168b295fc5c4d369ee6419de78e003398d2c1a14a772a9a
7
- data.tar.gz: f9521e71e1e5aaafea6d60f0c4bbd7f98f126bb0374e31f253a7eaaa9985c34d3a8dcd6eea697bbdbd3741ffcf1ddb0fdefae751efd0b8cc308659485305dcc4
6
+ metadata.gz: efae3f352fc6e1038583adb2aea3bbcb45963f972290c13d0f2a67d80db5209a9cab2eb7e80dc4bf8611f35bb4de8005eb5843cb97fdb363aa6fcc48b937f333
7
+ data.tar.gz: f484dc6b89b189e8dfcae29d71429639966b2e7836108c34d4dd58d7f4aa8b4d9f6fdd6915eb806f0a9d317b0bbac2cdcf1a65bca0bcf9c4cd12e3a14ee17a08
@@ -1,5 +1,5 @@
1
1
  AllCops:
2
- TargetRubyVersion: 2.3
2
+ TargetRubyVersion: 2.4
3
3
  Metrics/LineLength:
4
4
  Max: 120
5
5
  # To make it possible to copy or click on URIs in the code, we allow lines
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
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- activeset (0.8.5)
4
+ activeset (0.8.6)
5
5
  activesupport (>= 4.0.2)
6
6
 
7
7
  GEM
@@ -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.5'
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
- statement = merge_operation
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
- # in an ASC sort, nils float to the end of the list. In a DESC
21
- # sort, nils float to the start of the list. This is achieved by
22
- # wrapping each value_for_comparison in a tuple with 0 as the first
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.5
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-04 00:00:00.000000000 Z
11
+ date: 2019-05-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport