effective_resources 2.19.9 → 2.19.10

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: a64aa8daa41dc12a1702ee128d8a972ec46a005f616f2091f9821075c817f9c7
4
- data.tar.gz: c59a857b8b39855a74bfda837b59c259d92b192081c9af65947ad22de202d074
3
+ metadata.gz: dcc082069435ea9d5601f7d80eb676c1cbba2f63372659236151412c00f8feea
4
+ data.tar.gz: bed63eedbeb63602746e0e186d84d6f56c2635415ce9eff19a6e33e69aeb973a
5
5
  SHA512:
6
- metadata.gz: 71b49bf9d7152eeee999e1fffec4020355274f140c6c6e3bc4757cc8c69716808816bff5bf96b8332028ddedbf8ef24633616ea827118154bd7935aa0804a83a
7
- data.tar.gz: 1ff8ec49ce929e048e9582134447046c03448c7d0a2d0fb794c6024e83a03d705a9193a63336bd6fd7d4b0e64f1e08e44ceb2f54de281c175f3de0cb344170ac
6
+ metadata.gz: 60329f1197ae967e67df7cf12eb1e9be25d6074a8a8e8993fbfb29275e3deeeabb2fcca589f8d50c6278d7b9e54d2ebed8e29413c1f209f78501dddaa66d9f25
7
+ data.tar.gz: eadc102a68f6b214bce5664c04f0a4a5ad51c435b12f040d760a94e5667f6ed86522770c48b4456dd6638769e5385b3c934068c6ca21bd27886992d39e9c9c2c
@@ -78,7 +78,9 @@ module EffectiveResourcesHelper
78
78
 
79
79
  # Assign actions
80
80
  # We filter out any actions passed to us that aren't supported
81
- actions = if atts.key?(:actions)
81
+ actions = if atts.key?(:actions) && atts[:actions] == false
82
+ {}
83
+ elsif atts.key?(:actions)
82
84
  {}.tap do |actions|
83
85
  atts[:actions].each do |commit, opts|
84
86
  actions[commit] = opts if (effective_resource.actions.include?(opts[:action]) || opts[:path]).present?
@@ -24,13 +24,15 @@ module ActsAsEmailForm
24
24
  attr_accessor :email_form_subject
25
25
  attr_accessor :email_form_body
26
26
 
27
- effective_resource do
28
- email_form_action :string, permitted: true
29
- email_form_skip :boolean, permitted: true
30
-
31
- email_form_from :string, permitted: true
32
- email_form_subject :string, permitted: true
33
- email_form_body :text, permitted: true
27
+ if respond_to?(:effective_resource)
28
+ effective_resource do
29
+ email_form_action :string, permitted: true
30
+ email_form_skip :boolean, permitted: true
31
+
32
+ email_form_from :string, permitted: true
33
+ email_form_subject :string, permitted: true
34
+ email_form_body :text, permitted: true
35
+ end
34
36
  end
35
37
 
36
38
  with_options(if: -> { email_form_action.present? && !email_form_skip? }) do
@@ -394,6 +394,7 @@ module Effective
394
394
  end
395
395
 
396
396
  return relation.none() if columns.blank?
397
+
397
398
  search_columns_by_ilike_term(relation, value, columns: columns, fuzzy: fuzzy)
398
399
  end
399
400
 
@@ -404,42 +405,33 @@ module Effective
404
405
 
405
406
  value = value.to_s
406
407
 
407
- raise('unsupported OR and AND syntax') if value.include?(' OR ') && value.include?(' AND ')
408
- raise('expected columns') unless columns.present?
409
-
410
- terms = []
411
- join = ''
412
-
413
- if value.include?(' OR ')
414
- terms = value.split(' OR ')
415
- join = ' OR '
408
+ # Process search terms
409
+ terms = if value.include?(' OR ')
410
+ value.split(' OR ')
416
411
  elsif value.include?(' AND ')
417
- terms = value.split(' AND ')
418
- join = ' AND '
412
+ value.split(' AND ')
419
413
  else
420
- terms = value.split(' ')
421
- join = ' AND '
414
+ value.split(' ')
422
415
  end
423
416
 
424
417
  terms = (terms - [nil, '', ' ']).map(&:strip)
425
- columns = Array(columns)
426
- fuzzy = true if fuzzy.nil?
427
418
 
428
- terms = terms.inject({}) do |hash, term|
429
- hash["term_#{hash.length}".to_sym] = (fuzzy ? "%#{term}%" : term); hash
430
- end
431
-
432
- # Do any of these columns contain all the terms?
433
- conditions = columns.map do |name|
434
- column = (name.to_s.include?('.') ? name : sql_column(name))
435
- raise("expected an sql column for #{name}") if column.blank?
419
+ # Searching these columns with this behaviour
420
+ fuzzy = true if fuzzy.nil?
421
+ joiner = value.include?(' OR ') ? :or : :and
436
422
 
437
- keys = terms.keys.map { |key| (fuzzy ? "#{column} #{ilike} :#{key}" : "#{column} = :#{key}") }
438
- '(' + keys.join(' AND ') + ')'
439
- end.join(' OR ')
423
+ # Each term must match some column. Depending on the joiner, each term must match some column
424
+ terms.map do |term|
425
+ Array(columns).map do |name|
426
+ column = (name.to_s.include?('.') ? name : sql_column(name))
440
427
 
441
- # Do the search
442
- collection.where(conditions, terms)
428
+ if fuzzy
429
+ collection.where("#{column} #{ilike} ?", "%#{term}%")
430
+ else
431
+ collection.where("#{column} = ?", term)
432
+ end
433
+ end.inject(:or)
434
+ end.inject(joiner)
443
435
  end
444
436
 
445
437
  def order_by_associated_conditions(association, sort: nil, direction: :asc, limit: nil)
@@ -1,3 +1,3 @@
1
1
  module EffectiveResources
2
- VERSION = '2.19.9'.freeze
2
+ VERSION = '2.19.10'.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.19.9
4
+ version: 2.19.10
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: 2024-03-06 00:00:00.000000000 Z
11
+ date: 2024-03-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails