pattern_query_helper 0.1.8 → 0.1.9
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/lib/pattern_query_helper/associations.rb +2 -2
- data/lib/pattern_query_helper/filtering.rb +2 -2
- data/lib/pattern_query_helper/pagination.rb +15 -23
- data/lib/pattern_query_helper/sorting.rb +4 -4
- data/lib/pattern_query_helper/version.rb +1 -1
- data/lib/pattern_query_helper.rb +4 -4
- 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: caceb088a2059270acfce9119d5794089c9805b1
|
4
|
+
data.tar.gz: 8e6916e46207d6cbc92d4c3eb15fecd9267e80d8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ea414de0fdecea3f2a786d75a5abfd5c7f16eb3664a24262832da73260d7a4b03819faad2dccdb01b2362b9f49bc1dad756021f29ae7eb9915c2446a9a8d4391
|
7
|
+
data.tar.gz: df415343bc674682fc0684af8023bf91bab7737f637cae1704d57b7af468e8d740586921b24e8f452fcdee9db4eff64ec3642fd49547e3fe7dd2236021047002
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
module PatternQueryHelper
|
2
2
|
class Associations
|
3
|
-
def self.process_association_params(
|
4
|
-
associations
|
3
|
+
def self.process_association_params(associations)
|
4
|
+
associations ||= []
|
5
5
|
if associations.class == String
|
6
6
|
return [associations.to_sym]
|
7
7
|
else
|
@@ -1,7 +1,7 @@
|
|
1
1
|
module PatternQueryHelper
|
2
2
|
class Filtering
|
3
|
-
def self.create_filters(
|
4
|
-
filters
|
3
|
+
def self.create_filters(filters, column_map=nil, symbol_prefix="")
|
4
|
+
filters ||= {}
|
5
5
|
filter_string = "true = true"
|
6
6
|
filter_params = {}
|
7
7
|
filter_array = []
|
@@ -3,32 +3,24 @@ require 'kaminari'
|
|
3
3
|
|
4
4
|
module PatternQueryHelper
|
5
5
|
class Pagination
|
6
|
-
def self.parse_pagination_params(
|
7
|
-
if
|
8
|
-
|
9
|
-
include_all: true
|
10
|
-
}
|
6
|
+
def self.parse_pagination_params(page, per_page)
|
7
|
+
if page
|
8
|
+
page = page.to_i
|
11
9
|
else
|
12
|
-
|
13
|
-
page = params[:page].to_i
|
14
|
-
else
|
15
|
-
page = 1
|
16
|
-
end
|
17
|
-
if params[:per_page]
|
18
|
-
per_page = params[:per_page].to_i
|
19
|
-
else
|
20
|
-
per_page = 20
|
21
|
-
end
|
22
|
-
raise RangeError.new("page must be greater than 0") unless page > 0
|
23
|
-
raise RangeError.new("per_page must be greater than 0") unless per_page > 0
|
24
|
-
pagination_params = {
|
25
|
-
page: page.to_i,
|
26
|
-
per_page: per_page.to_i
|
27
|
-
}
|
10
|
+
page = 1
|
28
11
|
end
|
12
|
+
if per_page
|
13
|
+
per_page = per_page.to_i
|
14
|
+
else
|
15
|
+
per_page = 20
|
16
|
+
end
|
17
|
+
raise RangeError.new("page must be greater than 0") unless page > 0
|
18
|
+
raise RangeError.new("per_page must be greater than 0") unless per_page > 0
|
29
19
|
|
30
|
-
|
31
|
-
|
20
|
+
{
|
21
|
+
page: page,
|
22
|
+
per_page: per_page
|
23
|
+
}
|
32
24
|
end
|
33
25
|
|
34
26
|
def self.create_pagination_payload(count, pagination_params)
|
@@ -1,9 +1,9 @@
|
|
1
1
|
module PatternQueryHelper
|
2
2
|
class Sorting
|
3
|
-
def self.parse_sorting_params(
|
4
|
-
sort_sql= []
|
5
|
-
if
|
6
|
-
sorts =
|
3
|
+
def self.parse_sorting_params(sort)
|
4
|
+
sort_sql = []
|
5
|
+
if sort
|
6
|
+
sorts = sort.split(",")
|
7
7
|
sorts.each_with_index do |sort, index|
|
8
8
|
column = sort.split(":")[0]
|
9
9
|
direction = sort.split(":")[1]
|
data/lib/pattern_query_helper.rb
CHANGED
@@ -123,10 +123,10 @@ module PatternQueryHelper
|
|
123
123
|
end
|
124
124
|
|
125
125
|
def self.parse_helpers(params)
|
126
|
-
filtering = PatternQueryHelper::Filtering.create_filters(params)
|
127
|
-
sorting = PatternQueryHelper::Sorting.parse_sorting_params(params)
|
128
|
-
associations = PatternQueryHelper::Associations.process_association_params(params)
|
129
|
-
pagination = PatternQueryHelper::Pagination.parse_pagination_params(params)
|
126
|
+
filtering = PatternQueryHelper::Filtering.create_filters(params[:filter])
|
127
|
+
sorting = PatternQueryHelper::Sorting.parse_sorting_params(params[:sort])
|
128
|
+
associations = PatternQueryHelper::Associations.process_association_params(params[:include])
|
129
|
+
pagination = PatternQueryHelper::Pagination.parse_pagination_params(params[:page], params[:per_page])
|
130
130
|
|
131
131
|
{
|
132
132
|
filters: filtering,
|