like_query 0.1.5 → 0.1.6
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/like_query/model_extensions.rb +29 -7
- data/lib/like_query/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: c7de4a5d2ad260480095855c658997269624ccb606be9e38bd054342404bd7ad
|
4
|
+
data.tar.gz: 11f20847057ba089d2cf7020799f420bcf1f99ef2bc7aa09ed5a9a266a614725
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e2540e87f1eabbab29fd0f032e99e98029dfdfe6c558b7793fc3d63d8635171f76b110cd56ee0c34beca883908c1a32063c610f8af52f4f52223050e830006af
|
7
|
+
data.tar.gz: 458da755375fc2651a95a13f1c4722da0f85711f9742ba701fd0aa79b528f377852b01c222c1423287d7c731ed36dacc0eef61512b03271d89ae07599141aa3e
|
@@ -1,16 +1,20 @@
|
|
1
1
|
module LikeQuery
|
2
2
|
module ModelExtensions
|
3
3
|
|
4
|
-
def like(search_string, schema = nil)
|
4
|
+
def like(search_string, schema = nil, debug: false)
|
5
5
|
|
6
6
|
search_string = '' if !search_string
|
7
7
|
search_string = search_string.to_s unless search_string.is_a?(String)
|
8
|
+
schema = [schema] if schema.is_a?(Symbol)
|
9
|
+
@debug_like_query = debug
|
8
10
|
|
9
11
|
raise 'like can only be called from a model' if self == ApplicationRecord
|
12
|
+
if schema.first.is_a?(Array) && schema.length >= 2
|
13
|
+
raise "only one array can be given: Either schema as one array or as multiple args, not as array"
|
14
|
+
end
|
10
15
|
|
11
16
|
queries = nil
|
12
17
|
associations = []
|
13
|
-
schema = [schema] if schema.is_a?(Symbol)
|
14
18
|
@like_query_schema = schema
|
15
19
|
|
16
20
|
search_string.split(' ').each do |s|
|
@@ -18,13 +22,13 @@ module LikeQuery
|
|
18
22
|
f_str = format_string_element(s)
|
19
23
|
|
20
24
|
q = nil
|
21
|
-
|
22
|
-
raise "only one array can be given: Either schema as one array or as multiple args, not as array"
|
23
|
-
end
|
25
|
+
|
24
26
|
(schema.first.is_a?(Array) ? schema.first : schema).each do |p|
|
27
|
+
dbg("• Iterate schema => #{p}")
|
25
28
|
enum_lab = enum_keys(p, s)
|
26
29
|
if enum_lab.present?
|
27
30
|
q = arel_table[p].in(enum_lab)
|
31
|
+
dbg(-> { " Query from enum => #{q.to_sql}" })
|
28
32
|
elsif p.is_a?(Hash)
|
29
33
|
p.each do |k, v|
|
30
34
|
assoc = reflect_on_association(k)
|
@@ -134,11 +138,29 @@ module LikeQuery
|
|
134
138
|
|
135
139
|
if search_string[:float_from] && [:float, :decimal, :big_decimal, :integer, :bigint].include?(type)
|
136
140
|
|
137
|
-
arel.between(search_string[:float_from]..search_string[:float_until])
|
141
|
+
q = arel.between(search_string[:float_from]..search_string[:float_until])
|
142
|
+
dbg(-> { " Query from string-field => #{q.to_sql}" })
|
143
|
+
q
|
144
|
+
|
145
|
+
else
|
146
|
+
|
147
|
+
q = arel.matches(search_string[:string])
|
148
|
+
dbg(-> { " Query from string-field => #{q.to_sql}" })
|
149
|
+
q
|
150
|
+
|
151
|
+
end
|
152
|
+
end
|
153
|
+
|
154
|
+
def dbg(label)
|
155
|
+
|
156
|
+
return unless @debug_like_query
|
138
157
|
|
158
|
+
if label.is_a?(Proc)
|
159
|
+
lab = label.call
|
139
160
|
else
|
140
|
-
|
161
|
+
lab = label
|
141
162
|
end
|
163
|
+
Rails.logger.debug("LikeQuery: #{lab}")
|
142
164
|
end
|
143
165
|
end
|
144
166
|
end
|
data/lib/like_query/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: like_query
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- christian
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-11-
|
11
|
+
date: 2024-11-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|