rad_core_rails 0.5.3 → 0.5.4
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/lib/rad_core_rails/query_generator.rb +79 -12
- data/lib/rad_core_rails/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: 48f739f3efcd0dbc68c15a40a1342153a8a403b6e7fadc8e17c2ea77b87ebf34
|
4
|
+
data.tar.gz: 5827e62ec17c57d74b43f9027a2fa65989d7df2bee37c1b60c814cc1f2d00998
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: af53c0879f5c3bd089fa94a6b1644e2b7548bc8a583de55a838a10824a69f7790b6120360ff922f0c5d57021232a3f0c44c12522e31cb116483b718cb38ea457
|
7
|
+
data.tar.gz: 4f7d2ac6a1ca1056effe24ef813999e0e9b07a70d07ba320f5915471691aca34bacaefa90fffdd0d7740abc8626d7f221a6eee33312005410fd84e90bb03dd12
|
@@ -38,24 +38,89 @@ module RadCoreRails
|
|
38
38
|
[query.reject(&:blank?).join(' AND '), args]
|
39
39
|
end
|
40
40
|
|
41
|
+
# def generate_search_clause(search)
|
42
|
+
# and_args = []
|
43
|
+
# or_args = []
|
44
|
+
# if search.present? && searchable_columns.is_a?(Array)
|
45
|
+
# # search_term_size = search.split(' ').length
|
46
|
+
# and_terms = search.split(' ').select { |term| !term.include?('+') }
|
47
|
+
# or_terms = search.split(' ').select { |term| term.include?('+') }
|
48
|
+
# and_columns = []
|
49
|
+
# or_columns = []
|
50
|
+
# # just_ors = search_term_size == or_term_size
|
51
|
+
# # operand = just_ors ? 'OR' : 'AND'
|
52
|
+
# # search_terms = just_ors == true ? search.split(' ') : search.split(' ').select { |term| !term.include?('+') }
|
53
|
+
# and_terms.each do |term|
|
54
|
+
# columns = []
|
55
|
+
# and_terms.each do |col|
|
56
|
+
# and_columns.push("(LOWER(#{col}) ILIKE ?)")
|
57
|
+
# and_args.push '%' + term.downcase.strip + '%'
|
58
|
+
# end
|
59
|
+
# or_terms.each do |col|
|
60
|
+
# columns.push("(LOWER(#{col}) ILIKE ?)")
|
61
|
+
# or_args.push '%' + term[1, term.length].downcase.strip + '%'
|
62
|
+
# end
|
63
|
+
# clause = if or_columns.empty?
|
64
|
+
# '(' + and_columns.join(' OR ') + ')'
|
65
|
+
# else
|
66
|
+
# '(' + '(' + and_columns.join(' OR ') + ')' + 'AND' + '(' + or_columns.join(' OR ') + ')' + ')'
|
67
|
+
# end
|
68
|
+
# end
|
69
|
+
# [clause, and_args + or_args]
|
70
|
+
# else
|
71
|
+
# ['', []]
|
72
|
+
# end
|
73
|
+
# end
|
74
|
+
|
75
|
+
# @searchable_columns, is an array of column names that you can compare to your terms.
|
76
|
+
#
|
41
77
|
def generate_search_clause(search)
|
42
|
-
args = []
|
43
78
|
if search.present? && searchable_columns.is_a?(Array)
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
79
|
+
# holds all of the sql from sanitized_and_terms
|
80
|
+
and_args = []
|
81
|
+
# holds all the table columns sql for all the AND terms
|
82
|
+
and_clause = []
|
83
|
+
# holds all of the sql from sanitized_or_terms
|
84
|
+
or_args = []
|
85
|
+
# holds all the table columns sql for all the OR terms
|
86
|
+
or_clause = []
|
87
|
+
# extract and terms, remove casing, and add ILIKE '%' comparisions
|
88
|
+
sanitized_and_terms = search.split(' ')
|
89
|
+
.reject { |term| term.include?('+') }
|
90
|
+
.map { |term| '%' + term.downcase.strip + '%' }
|
91
|
+
# extract or terms, remove casing, and add ILIKE '%' comparisions
|
92
|
+
sanitized_or_terms = search.split(' ')
|
93
|
+
.select { |term| term.include?('+') }
|
94
|
+
.map { |term| '%' + term[1, term.length].downcase.strip + '%' }
|
95
|
+
# loop through sanitized_and_terms to find all possible columns.
|
96
|
+
sanitized_and_terms.each do |sanitized_term|
|
97
|
+
columns = []
|
98
|
+
# all possible columns where this should be searched
|
99
|
+
searchable_columns.each do |col|
|
100
|
+
columns.push("(LOWER(#{col}) ILIKE ?)")
|
101
|
+
and_args.push sanitized_term
|
102
|
+
end
|
103
|
+
and_clause.push '(' + columns.join(' OR ') + ')'
|
104
|
+
end
|
105
|
+
# loop through sanitized_or_terms to find all possible columns.
|
106
|
+
sanitized_or_terms.each do |sanitized_term|
|
51
107
|
columns = []
|
108
|
+
# all possible columns where this should be searched
|
52
109
|
searchable_columns.each do |col|
|
53
110
|
columns.push("(LOWER(#{col}) ILIKE ?)")
|
54
|
-
|
111
|
+
or_args.push sanitized_term
|
55
112
|
end
|
56
|
-
|
113
|
+
or_clause.push '(' + columns.join(' OR ') + ')'
|
114
|
+
end
|
115
|
+
if or_clause.empty? && and_clause.empty?
|
116
|
+
['', []]
|
117
|
+
elsif or_clause.empty?
|
118
|
+
['(' + and_clause.join(' AND ') + ')', and_args]
|
119
|
+
elsif and_clause.empty?
|
120
|
+
['(' + or_clause.join(' OR ') + ')', or_args]
|
121
|
+
else
|
122
|
+
['((' + and_clause.join(' AND ') + ') AND (' + or_clause.join(' OR ') + '))', and_args + or_args]
|
57
123
|
end
|
58
|
-
['(' + clause.join(" #{operand} ") + ')', args]
|
59
124
|
else
|
60
125
|
['', []]
|
61
126
|
end
|
@@ -74,7 +139,9 @@ module RadCoreRails
|
|
74
139
|
str = if optional_exclusion_clause.present? && filter[:option] == '!='
|
75
140
|
optional_exclusion_clause
|
76
141
|
else
|
77
|
-
|
142
|
+
# probably should fix this.
|
143
|
+
# somtimes we arent sending a filter option, so just default it to =
|
144
|
+
"(#{column_name} #{filter[:option] || '='} ANY(ARRAY[?]))"
|
78
145
|
end
|
79
146
|
args = [filter[:values]]
|
80
147
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rad_core_rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.5.
|
4
|
+
version: 0.5.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Oleksandr Poltavets, James Marrs
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-11-
|
11
|
+
date: 2020-11-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|