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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d80b1ac39e887931fa741b1b0d5e8e3eac8e86b3
4
- data.tar.gz: 6b42d27cd476ee84ad1438a220d7230c35484182
3
+ metadata.gz: caceb088a2059270acfce9119d5794089c9805b1
4
+ data.tar.gz: 8e6916e46207d6cbc92d4c3eb15fecd9267e80d8
5
5
  SHA512:
6
- metadata.gz: b788897d5d99e1f236d07906a2ecf2217c25e2dd2ce20d2a3e8299576103a2708f7a89542b6e14d68a165aa2bb52804a634ee51cb134eaf0f03ee535c1a2dff0
7
- data.tar.gz: 851a0726152bdfed51bcd0cb15c99a3142a1779f3a7c068e4e00cdcad2bed4857a99a1b61731d0b7807a3aa4bdcc02dfa978419acd3730f787dd7d27c8a23d62
6
+ metadata.gz: ea414de0fdecea3f2a786d75a5abfd5c7f16eb3664a24262832da73260d7a4b03819faad2dccdb01b2362b9f49bc1dad756021f29ae7eb9915c2446a9a8d4391
7
+ data.tar.gz: df415343bc674682fc0684af8023bf91bab7737f637cae1704d57b7af468e8d740586921b24e8f452fcdee9db4eff64ec3642fd49547e3fe7dd2236021047002
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- pattern_query_helper (0.1.8)
4
+ pattern_query_helper (0.1.9)
5
5
  activerecord (~> 5.0)
6
6
  kaminari
7
7
 
@@ -1,7 +1,7 @@
1
1
  module PatternQueryHelper
2
2
  class Associations
3
- def self.process_association_params(params)
4
- associations = params[:include] || []
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(params, column_map=nil, symbol_prefix="")
4
- filters = params[:filter] || {}
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(params)
7
- if params[:per_page] == 'all'
8
- pagination_params = {
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
- if params[:page]
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
- pagination_params
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(params)
4
- sort_sql= []
5
- if params[:sort]
6
- sorts = params[:sort].split(",")
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]
@@ -1,3 +1,3 @@
1
1
  module PatternQueryHelper
2
- VERSION = "0.1.8"
2
+ VERSION = "0.1.9"
3
3
  end
@@ -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,
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pattern_query_helper
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.8
4
+ version: 0.1.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Evan McDaniel