data_tables-responder 0.2.1 → 0.2.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/data_tables/modules/search.rb +28 -24
- data/lib/data_tables/responder/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0798fa16c1404198a97647a9bfc2f4514f3a21e4
|
4
|
+
data.tar.gz: 04e1541db4c718874ecbf131613569b34ebadf30
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 030493b51f5b002e10b36561b9ec9dbd900c457ab3159f000c19091caccd757cc506e79901d61d321f546422e40eb160b24ea0c0ff00a28fc61e76538e049957
|
7
|
+
data.tar.gz: 08eb69d5a37e099868c9869f2a66e1959cf3fd02fa19f86b94a3e05bd5ca2dcba472272456a980d27c5459fcefa733bb4f70bb172d5983e493f0090fa9052652
|
@@ -26,35 +26,39 @@ module DataTables
|
|
26
26
|
|
27
27
|
searches = DataTables.flat_keys_to_nested columns
|
28
28
|
|
29
|
-
|
30
|
-
search_by = searches.collect do |k, query|
|
31
|
-
if query.is_a? Hash
|
32
|
-
assoc = model.reflect_on_association(k)
|
33
|
-
assoc_klass = assoc.klass
|
34
|
-
assoc_arel_table = assoc_klass.arel_table
|
29
|
+
search_by = build_search(model, searches)
|
35
30
|
|
36
|
-
|
37
|
-
|
38
|
-
else
|
39
|
-
@collection = @collection.includes(k).references(k)
|
40
|
-
end
|
31
|
+
@collection.where(search_by.reduce(:or))
|
32
|
+
end
|
41
33
|
|
42
|
-
|
34
|
+
def build_search(model, searches)
|
35
|
+
queries = []
|
36
|
+
searches.inject(queries) do |query, junk|
|
37
|
+
column, search = junk
|
38
|
+
case search
|
39
|
+
when Hash
|
40
|
+
assoc = model.reflect_on_association(column)
|
41
|
+
assoc_klass = assoc.klass
|
42
|
+
|
43
|
+
outer_join = Arel::Nodes::OuterJoin.new(assoc_klass.arel_table,
|
44
|
+
Arel::Nodes::On.new(
|
45
|
+
model.arel_table[assoc.active_record_primary_key].eq(assoc_klass.arel_table[assoc.foreign_key])
|
46
|
+
))
|
47
|
+
@collection.joins(outer_join)
|
48
|
+
query << build_search(assoc_klass, search).reduce(:or)
|
43
49
|
else
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
end
|
50
|
+
col_s = column.to_s
|
51
|
+
case (k = model.columns.find(nil) { |c| c.name == col_s })&.type
|
52
|
+
when :string
|
53
|
+
query << model.arel_table[k.name].matches("%#{search}%")
|
54
|
+
when :integer
|
55
|
+
query << model.arel_table[k.name].eq(search)
|
56
|
+
else
|
57
|
+
query
|
53
58
|
end
|
54
59
|
end
|
55
|
-
end
|
56
|
-
|
57
|
-
@collection.where(search_by.reduce(:or))
|
60
|
+
end
|
61
|
+
queries
|
58
62
|
end
|
59
63
|
|
60
64
|
protected
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: data_tables-responder
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dale Stevens
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-01-
|
11
|
+
date: 2017-01-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: active_model_serializers
|