forest_liana 1.0.0.pre.beta.1 → 1.0.0.pre.beta.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/services/forest_liana/resources_getter.rb +31 -10
- data/lib/forest_liana/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 96387ca6684d93d492164c89a8047c8a1c856868
|
4
|
+
data.tar.gz: e8b02d496b3fc2fcc1912cb4046bb4a9f3cda639
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 100ec457f01ffc78b7805244522740730a9fb96e3fd46bbd039f5dc579fdb635a07f6e76dac6d10853cc0ec062cb07d5bdef74623532d07bad3409c0c8453805
|
7
|
+
data.tar.gz: 84c3823fc6e4554f533f2fa3744354ee6ab2301eed00bfe9766a85eabb7b8a75fb1e81c6e90afe4cea520a4a0199663846b7d23181443ee5eb9765942104369b
|
@@ -21,31 +21,52 @@ module ForestLiana
|
|
21
21
|
private
|
22
22
|
|
23
23
|
def search_query
|
24
|
-
SearchQueryBuilder.new(@resource.
|
24
|
+
SearchQueryBuilder.new(@resource.joins(includes), @params).perform
|
25
25
|
end
|
26
26
|
|
27
27
|
def sort_query
|
28
|
-
query =
|
28
|
+
query = nil
|
29
29
|
|
30
30
|
if @params[:sort]
|
31
31
|
@params[:sort].split(',').each do |field|
|
32
|
-
order = :
|
33
|
-
|
34
|
-
|
35
|
-
field.slice!(0)
|
36
|
-
end
|
32
|
+
order = detect_sort_order(@params[:sort])
|
33
|
+
field.slice!(0) if order == :desc
|
34
|
+
field = detect_reference(field)
|
37
35
|
|
38
|
-
query
|
36
|
+
query = "#{field} #{order.upcase}"
|
39
37
|
end
|
40
38
|
elsif @resource.column_names.include?('created_at')
|
41
|
-
query
|
39
|
+
query = 'created_at DESC'
|
42
40
|
elsif @resource.column_names.include?('id')
|
43
|
-
query
|
41
|
+
query = 'id DESC'
|
42
|
+
else
|
43
|
+
return @records
|
44
44
|
end
|
45
45
|
|
46
46
|
@records.order(query)
|
47
47
|
end
|
48
48
|
|
49
|
+
def detect_sort_order(field)
|
50
|
+
return (if field[0] == '-' then :desc else :asc end)
|
51
|
+
end
|
52
|
+
|
53
|
+
def detect_reference(param)
|
54
|
+
ref, field = param.split('.')
|
55
|
+
|
56
|
+
if ref && field
|
57
|
+
association = @resource.reflect_on_all_associations
|
58
|
+
.find {|a| a.name == ref.to_sym }
|
59
|
+
|
60
|
+
if association
|
61
|
+
"#{association.class_name.to_s.underscore.pluralize}.#{field}"
|
62
|
+
else
|
63
|
+
param
|
64
|
+
end
|
65
|
+
else
|
66
|
+
param
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
49
70
|
def includes
|
50
71
|
@resource
|
51
72
|
.reflect_on_all_associations
|
data/lib/forest_liana/version.rb
CHANGED