effective_resources 2.7.11 → 2.7.12
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/models/effective/resources/relation.rb +32 -9
- data/lib/effective_resources/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 52098eedae0bfee156714b0ad5e2d2a209e542d56256f3d5104d8d1d63c7a97c
|
4
|
+
data.tar.gz: ddc812ec61b5bb6c959013074cbd91e08af99df211892511228760cb4555c5df
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
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
|
-
|
391
|
+
def search_columns_by_ilike_term(collection, value, columns:, fuzzy: nil)
|
392
|
+
return collection if value.blank?
|
388
393
|
|
389
|
-
|
390
|
-
|
391
|
-
|
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(
|
425
|
+
).join(join)
|
401
426
|
|
402
|
-
searched =
|
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
|
|
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.
|
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
|
+
date: 2023-05-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|