like_query 0.1.7 → 0.1.9
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 +16 -11
- data/lib/like_query/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 218fe9ef241c396ed43d5a0daffe4fb69fceccf534b2b15b425eca0e56cd5f0d
|
|
4
|
+
data.tar.gz: a3a37469d41c7ec574868480691dd727c61a8908ad34816c23297775b830323c
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 134b7f5d618b4828a973de21a34250bc16cae0cfe086819cd4927a99941e4ba6cde50b1c2883feb4a63cc413333234076b15f7dfa3e8cbc81878692e04028481
|
|
7
|
+
data.tar.gz: 19ed347cd40c60819bf56d7ffdf28e6c64b183367bb5e9f11282cf8fec89450a95df0e88b623f477c2eeacb4f2c66f5877dd224e91c0235eaf9806205b088a7c
|
|
@@ -13,7 +13,7 @@ module LikeQuery
|
|
|
13
13
|
raise "only one array can be given: Either schema as one array or as multiple args, not as array"
|
|
14
14
|
end
|
|
15
15
|
|
|
16
|
-
queries =
|
|
16
|
+
queries = []
|
|
17
17
|
associations = []
|
|
18
18
|
@like_query_schema = schema
|
|
19
19
|
|
|
@@ -21,14 +21,17 @@ module LikeQuery
|
|
|
21
21
|
|
|
22
22
|
f_str = format_string_element(s)
|
|
23
23
|
|
|
24
|
-
q =
|
|
24
|
+
q = []
|
|
25
25
|
|
|
26
26
|
(schema.first.is_a?(Array) ? schema.first : schema).each do |p|
|
|
27
27
|
dbg("• Iterate schema => #{p}")
|
|
28
28
|
enum_lab = enum_keys(p, s)
|
|
29
|
+
|
|
29
30
|
if enum_lab.present?
|
|
30
|
-
|
|
31
|
-
dbg(-> { " Query from enum => #{
|
|
31
|
+
_q = arel_table[p].in(enum_lab).to_sql
|
|
32
|
+
dbg(-> { " Query from enum => #{_q}" })
|
|
33
|
+
q.push(_q)
|
|
34
|
+
|
|
32
35
|
elsif p.is_a?(Hash)
|
|
33
36
|
p.each do |k, v|
|
|
34
37
|
assoc = reflect_on_association(k)
|
|
@@ -37,36 +40,38 @@ module LikeQuery
|
|
|
37
40
|
if v.is_a?(Symbol) || v.is_a?(String)
|
|
38
41
|
_q = create_arel(v, f_str, assoc)
|
|
39
42
|
if _q.present?
|
|
40
|
-
q
|
|
43
|
+
q.push(_q.to_sql)
|
|
41
44
|
end
|
|
42
45
|
elsif v.is_a?(Array)
|
|
43
46
|
v.each do |_v|
|
|
44
47
|
_q = create_arel(_v, f_str, assoc)
|
|
45
48
|
if _q.present?
|
|
46
|
-
q
|
|
49
|
+
q.push(_q.to_sql)
|
|
47
50
|
end
|
|
48
51
|
end
|
|
49
52
|
else
|
|
50
53
|
raise "unknown element: #{p}"
|
|
51
54
|
end
|
|
52
55
|
end
|
|
56
|
+
|
|
53
57
|
else
|
|
54
58
|
_q = create_arel(p, f_str)
|
|
55
59
|
if _q.present?
|
|
56
|
-
q
|
|
60
|
+
q.push(_q.to_sql)
|
|
57
61
|
end
|
|
62
|
+
|
|
58
63
|
end
|
|
59
64
|
|
|
60
65
|
end
|
|
61
|
-
queries
|
|
66
|
+
queries.push("(#{q.join(' OR ')})")
|
|
62
67
|
end
|
|
63
68
|
|
|
64
69
|
if associations.present?
|
|
65
|
-
r = left_outer_joins(associations).where(queries)
|
|
70
|
+
r = left_outer_joins(associations).where(queries.join(" AND "))
|
|
66
71
|
dbg(->{"RESULT => #{r.to_sql}"})
|
|
67
72
|
r
|
|
68
73
|
else
|
|
69
|
-
r = where(queries)
|
|
74
|
+
r = where(queries.join(" AND "))
|
|
70
75
|
dbg(->{"RESULT => #{r.to_sql}"})
|
|
71
76
|
r
|
|
72
77
|
end
|
|
@@ -139,7 +144,7 @@ module LikeQuery
|
|
|
139
144
|
if search_string[:float_from] && [:float, :decimal, :big_decimal, :integer, :bigint].include?(type)
|
|
140
145
|
|
|
141
146
|
q = arel.between(search_string[:float_from]..search_string[:float_until])
|
|
142
|
-
dbg(-> { " Query from
|
|
147
|
+
dbg(-> { " Query from number-field => #{q.to_sql}" })
|
|
143
148
|
q
|
|
144
149
|
|
|
145
150
|
else
|
data/lib/like_query/version.rb
CHANGED