effective_resources 2.7.10 → 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 +4 -4
- data/app/models/effective/resources/relation.rb +39 -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}%"))
|
@@ -350,6 +350,13 @@ module Effective
|
|
350
350
|
when :gteq then relation.where(attribute.gteq(term))
|
351
351
|
when :lt then relation.where(attribute.lt(term))
|
352
352
|
when :lteq then relation.where(attribute.lteq(term))
|
353
|
+
when :days_ago_eq
|
354
|
+
date = (Time.zone.now - (term.to_i).days)
|
355
|
+
relation.where("#{sql_column} >= ? AND #{sql_column} <= ?", date.beginning_of_day, date.end_of_day)
|
356
|
+
when :days_ago_lteq # 30 days or less ago.
|
357
|
+
relation.where("#{sql_column} >= ?", Time.zone.now - (term.to_i).days)
|
358
|
+
when :days_ago_gteq # 30 days or more ago
|
359
|
+
relation.where("#{sql_column} <= ?", Time.zone.now - (term.to_i).days)
|
353
360
|
else raise("Unexpected operation: #{operation}")
|
354
361
|
end
|
355
362
|
end
|
@@ -376,12 +383,37 @@ module Effective
|
|
376
383
|
end
|
377
384
|
|
378
385
|
return relation.none() if columns.blank?
|
386
|
+
search_columns_by_ilike_term(relation, value, columns: columns, fuzzy: fuzzy)
|
387
|
+
end
|
388
|
+
|
389
|
+
private
|
379
390
|
|
380
|
-
|
391
|
+
def search_columns_by_ilike_term(collection, value, columns:, fuzzy: nil)
|
392
|
+
return collection if value.blank?
|
381
393
|
|
382
|
-
|
383
|
-
|
384
|
-
|
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
|
385
417
|
|
386
418
|
terms.each do |term|
|
387
419
|
conditions = (
|
@@ -390,16 +422,14 @@ module Effective
|
|
390
422
|
else
|
391
423
|
columns.map { |name| "#{sql_column(name)} = :term" }
|
392
424
|
end
|
393
|
-
).join(
|
425
|
+
).join(join)
|
394
426
|
|
395
|
-
searched =
|
427
|
+
searched = collection.where(conditions, fuzzy: "%#{term}%", term: term)
|
396
428
|
end
|
397
429
|
|
398
430
|
searched
|
399
431
|
end
|
400
432
|
|
401
|
-
private
|
402
|
-
|
403
433
|
def order_by_associated_conditions(association, sort: nil, direction: :asc, limit: nil)
|
404
434
|
resource = Effective::Resource.new(association)
|
405
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
|