effective_resources 2.7.19 → 2.8.0

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: 1f3c2935ca26bb5e2275b6d035bc98fa19f6fdb0bb63be57b1f45a7dc6a46a93
4
- data.tar.gz: 7a61e1b4d7a7ad0fbd7834fb930f10a1a860699a578f6eaeaf227f2a121173bf
3
+ metadata.gz: 750ef0ae89d5b6437e046369b0dc46811abfa26ace4559e9448b190c1e255430
4
+ data.tar.gz: 7ad14d23604419ba975ab11addf2912f7fbcefe40fdaa9764c7782a2c992cc3d
5
5
  SHA512:
6
- metadata.gz: 0a9c46b85be8c1cec2b70787ac4a8413b2694e574a9b82937faf18ff35b5f1fac015585d16e25a84962a87fce0aed032fa45a9097b56c26c868b30c6844441c0
7
- data.tar.gz: 4ed252ae6da3efe34ebca6a5591c5690c33e4d7ee3029f80c695767a66534ec17a623eeb9bf2a1b579e0ee57337be6cfcd3803e9504fd4027406c0ea8fcdf2e2
6
+ metadata.gz: 6b79973ce6e33a95e792921ecf6cc548fa144b9fb2aa5b550e531f1d7aa613d00e39aa301b71ab802c0e1506c7f31dba6344925e188f2efd3f78a0e071e24efa
7
+ data.tar.gz: 4bd4b421e3e74108cd95a84cb3283f0740aab2f890532901f5cf0e52b4d4680383c75351612e6d9b59b5cd6f546e844e5d8120ea13c34cc1960cabd503670d6b
@@ -62,6 +62,9 @@ module Effective
62
62
  when :string, :text
63
63
  relation
64
64
  .order(Arel.sql(("ISNULL(#{sql_column}), " if mysql?).to_s + "#{sql_column}='' ASC, #{sql_column} #{sql_direction}" + (" NULLS LAST" if postgres?).to_s))
65
+ when :date, :datetime
66
+ relation
67
+ .order(Arel.sql(("ISNULL(#{sql_column}), " if mysql?).to_s + "#{sql_column} #{sql_direction}" + (" NULLS LAST" if postgres?).to_s))
65
68
  else
66
69
  relation
67
70
  .order(Arel.sql("#{sql_column} #{sql_direction}"))
@@ -410,29 +413,25 @@ module Effective
410
413
  join = ' AND '
411
414
  else
412
415
  terms = value.split(' ')
413
- join = ' OR '
416
+ join = ' AND '
414
417
  end
415
418
 
416
419
  terms = (terms - [nil, '', ' ']).map(&:strip)
417
420
  columns = Array(columns)
418
421
  fuzzy = true if fuzzy.nil?
419
422
 
420
- # Do the search
421
- searched = collection
422
-
423
- terms.each do |term|
424
- conditions = (
425
- if fuzzy
426
- columns.map { |name| "#{sql_column(name)} #{ilike} :fuzzy" }
427
- else
428
- columns.map { |name| "#{sql_column(name)} = :term" }
429
- end
430
- ).join(join)
431
-
432
- searched = collection.where(conditions, fuzzy: "%#{term}%", term: term)
423
+ terms = terms.inject({}) do |hash, term|
424
+ hash["term_#{hash.length}".to_sym] = (fuzzy ? "%#{term}%" : term); hash
433
425
  end
434
426
 
435
- searched
427
+ # Do any of these columns contain all the terms?
428
+ conditions = columns.map do |name|
429
+ keys = terms.keys.map { |key| (fuzzy ? "#{sql_column(name)} #{ilike} :#{key}" : "#{sql_column(name)} = :#{key}") }
430
+ '(' + keys.join(' AND ') + ')'
431
+ end.join(' OR ')
432
+
433
+ # Do the search
434
+ collection.where(conditions, terms)
436
435
  end
437
436
 
438
437
  def order_by_associated_conditions(association, sort: nil, direction: :asc, limit: nil)
@@ -1,3 +1,3 @@
1
1
  module EffectiveResources
2
- VERSION = '2.7.19'.freeze
2
+ VERSION = '2.8.0'.freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: effective_resources
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.7.19
4
+ version: 2.8.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Code and Effect
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-06-07 00:00:00.000000000 Z
11
+ date: 2023-06-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails