effective_resources 2.7.11 → 2.7.12

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d337f18fe69722ae972a31d8027af508b555b6542496e626d7793dacec6f2a17
4
- data.tar.gz: 44cb8d6fce0394a2dee68cd4731e3aea349d9edf2a8eed46026afe26e76838a0
3
+ metadata.gz: 52098eedae0bfee156714b0ad5e2d2a209e542d56256f3d5104d8d1d63c7a97c
4
+ data.tar.gz: ddc812ec61b5bb6c959013074cbd91e08af99df211892511228760cb4555c5df
5
5
  SHA512:
6
- metadata.gz: 45c1f94eba3ba91769fb8b6e356333405e2dd826e6ab14657abe7feaeec9635ce05f75554929ac140ad295d3759180dd04aa208adfe67bae6fcb8d70ee5a489c
7
- data.tar.gz: a324bf7e82198921d34b19f341c8e36bb72ff4225dd7b9bbd6b94d4e30cf6d8aa131fc69700c6da6fc4d2ceb45efd784e9bcf50d64f2d095d526c6c672591416
6
+ metadata.gz: c5dae027cd6b7cb940b321f35e8119c3ec26f7f6fef5e1cdbd5a9ff7e9ef6bdf114fc18fe939a872f6beb7885b41edd0eaacb86e43309e35bd8d39ab0a6f5ba7
7
+ data.tar.gz: 3cd24f5cfef41bb50f513cb592be063eb03975aa6e208d0c46b73f42dd722860b370cb218f7f83840deee84d92f5fa1da976182cacc9d85e926dc985e4c172b6
@@ -341,7 +341,7 @@ module Effective
341
341
 
342
342
  case operation
343
343
  when :eq then relation.where("#{sql_column} = ?", term)
344
- when :matches then relation.where("#{sql_column} #{ilike} ?", "%#{term}%")
344
+ when :matches then search_columns_by_ilike_term(relation, term, columns: name)
345
345
  when :not_eq then relation.where(attribute.not_eq(term))
346
346
  when :does_not_match then relation.where(attribute.does_not_match("%#{term}%"))
347
347
  when :starts_with then relation.where(attribute.matches("#{term}%"))
@@ -383,12 +383,37 @@ module Effective
383
383
  end
384
384
 
385
385
  return relation.none() if columns.blank?
386
+ search_columns_by_ilike_term(relation, value, columns: columns, fuzzy: fuzzy)
387
+ end
388
+
389
+ private
386
390
 
387
- fuzzy = true unless fuzzy == false
391
+ def search_columns_by_ilike_term(collection, value, columns:, fuzzy: nil)
392
+ return collection if value.blank?
388
393
 
389
- # Retval
390
- searched = relation
391
- terms = value.split(' ') - [nil, '']
394
+ raise('unsupported OR and AND syntax') if value.include?(' OR ') && value.include?(' AND ')
395
+ raise('expected columns') unless columns.present?
396
+
397
+ terms = []
398
+ join = ''
399
+
400
+ if value.include?(' OR ')
401
+ terms = value.split(' OR ')
402
+ join = ' OR '
403
+ elsif value.include?(' AND ')
404
+ terms = value.split(' AND ')
405
+ join = ' AND '
406
+ else
407
+ terms = value.split(' ')
408
+ join = ' OR '
409
+ end
410
+
411
+ terms = (terms - [nil, '', ' ']).map(&:strip)
412
+ columns = Array(columns)
413
+ fuzzy = true if fuzzy.nil?
414
+
415
+ # Do the search
416
+ searched = collection
392
417
 
393
418
  terms.each do |term|
394
419
  conditions = (
@@ -397,16 +422,14 @@ module Effective
397
422
  else
398
423
  columns.map { |name| "#{sql_column(name)} = :term" }
399
424
  end
400
- ).join(' OR ')
425
+ ).join(join)
401
426
 
402
- searched = searched.where(conditions, fuzzy: "%#{term}%", term: term)
427
+ searched = collection.where(conditions, fuzzy: "%#{term}%", term: term)
403
428
  end
404
429
 
405
430
  searched
406
431
  end
407
432
 
408
- private
409
-
410
433
  def order_by_associated_conditions(association, sort: nil, direction: :asc, limit: nil)
411
434
  resource = Effective::Resource.new(association)
412
435
 
@@ -1,3 +1,3 @@
1
1
  module EffectiveResources
2
- VERSION = '2.7.11'.freeze
2
+ VERSION = '2.7.12'.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.11
4
+ version: 2.7.12
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-05-11 00:00:00.000000000 Z
11
+ date: 2023-05-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails