pattern_query_helper 0.1.2 → 0.1.3

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: 46a21200973a9a7ef991273e4f33bc5ae303b629
4
- data.tar.gz: 0ad956c2e24bb70558ca9d1ab8d4e11ff82e3c7f
3
+ metadata.gz: a793c720df496cc279d3d86683056cc0193cd9ce
4
+ data.tar.gz: 89b26c1e5e760a05d22f8cd99cc4027bf63c6bd1
5
5
  SHA512:
6
- metadata.gz: a8fc381457c1b6108db43f9353bcac5c4f31ac8a88ae0e37ede34ab8f452655e22854500dc8236be1fe311dd15563849cc8f1d152c2111391e5a2fc75a93a48a
7
- data.tar.gz: 8ab06c771c9e42b2934305a2b2972a680e423eabc7ba405282b90cd9aec3832ea74661955d29f8f39b653bd86bdbdb509b35a76fd29007a81f64ea0bf16eb55c
6
+ metadata.gz: '021168529aaef384c4c32c5d632aebf035a015f15f5f3d7f28fd25225c3829f4b97c41b9ec9b280d203c6dee71e95c3ffd505aad470bb7e84f1b77857df2d131'
7
+ data.tar.gz: 4193cdd182b61699046e1fd1108eb12815246022aae9eef75a89e0a347625633c06e2cf369bcc5a6dd78142ab7d17017625b2100b975600d6945f9f0f68c4932
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- pattern_query_helper (0.1.2)
4
+ pattern_query_helper (0.1.3)
5
5
  activerecord (~> 5.0)
6
6
  kaminari
7
7
 
@@ -7,23 +7,23 @@ require "pattern_query_helper/sql"
7
7
 
8
8
  module PatternQueryHelper
9
9
  def self.paginated_sql_query(model, query, query_params, url_params)
10
- parse_params(url_params)
10
+ query_helpers = parse_params(url_params)
11
11
 
12
12
  query_config = {
13
13
  model: model,
14
14
  query: query,
15
15
  query_params: query_params,
16
- page: @pagination[:page],
17
- per_page: @pagination[:per_page],
18
- filter_string: @filtering[:filter_string],
19
- filter_params: @filtering[:filter_params],
20
- sort_string: @sorting,
16
+ page: query_helpers[:pagination][:page],
17
+ per_page: query_helpers[:pagination][:per_page],
18
+ filter_string: query_helpers[:filters][:filter_string],
19
+ filter_params: query_helpers[:filters][:filter_params],
20
+ sort_string: query_helpers[:sorting],
21
21
  }
22
22
 
23
23
  data = PatternQueryHelper::Sql.sql_query(query_config)
24
- data = PatternQueryHelper::Associations.load_associations(data, @associations)
24
+ data = PatternQueryHelper::Associations.load_associations(data, query_helpers[:associations])
25
25
  count = PatternQueryHelper::Sql.sql_query_count(query_config)
26
- pagination = PatternQueryHelper::Pagination.create_pagination_payload(count, @pagination)
26
+ pagination = PatternQueryHelper::Pagination.create_pagination_payload(count, query_helpers[:pagination])
27
27
 
28
28
  {
29
29
  pagination: pagination,
@@ -32,19 +32,19 @@ module PatternQueryHelper
32
32
  end
33
33
 
34
34
  def self.sql_query(model, query, query_params, url_params)
35
- parse_params(url_params)
35
+ query_helpers = parse_params(url_params)
36
36
 
37
37
  query_config = {
38
38
  model: model,
39
39
  query: query,
40
40
  query_params: query_params,
41
- filter_string: @filtering[:filter_string],
42
- filter_params: @filtering[:filter_params],
43
- sort_string: @sorting,
41
+ filter_string: query_helpers[:filters][:filter_string],
42
+ filter_params: query_helpers[:filters][:filter_params],
43
+ sort_string: query_helpers[:sorting],
44
44
  }
45
45
 
46
46
  data = PatternQueryHelper::Sql.sql_query(query_config)
47
- data = PatternQueryHelper::Associations.load_associations(data, @associations)
47
+ data = PatternQueryHelper::Associations.load_associations(data, query_helpers[:associations])
48
48
 
49
49
  {
50
50
  data: data
@@ -52,19 +52,19 @@ module PatternQueryHelper
52
52
  end
53
53
 
54
54
  def self.single_record_sql_query(model, query, query_params, url_params)
55
- parse_params(url_params)
55
+ query_helpers = parse_params(url_params)
56
56
 
57
57
  query_config = {
58
58
  model: model,
59
59
  query: query,
60
60
  query_params: query_params,
61
- filter_string: @filtering[:filter_string],
62
- filter_params: @filtering[:filter_params],
63
- sort_string: @sorting,
61
+ filter_string: query_helpers[:filters][:filter_string],
62
+ filter_params: query_helpers[:filters][:filter_params],
63
+ sort_string: query_helpers[:sorting],
64
64
  }
65
65
 
66
66
  data = PatternQueryHelper::Sql.single_record_query(query_config)
67
- data = PatternQueryHelper::Associations.load_associations(data, @associations)
67
+ data = PatternQueryHelper::Associations.load_associations(data, query_helpers[:associations])
68
68
 
69
69
  {
70
70
  data: data
@@ -72,22 +72,22 @@ module PatternQueryHelper
72
72
  end
73
73
 
74
74
  def self.active_record_query(active_record_call, url_params)
75
- parse_params(url_params)
76
- filtered_query = PatternQueryHelper::Filtering.filter_active_record_query(active_record_call, @filtering)
77
- sorted_query = PatternQueryHelper::Sorting.sort_active_record_query(active_record_call, @sorting)
78
- with_associations = PatternQueryHelper::Associations.load_associations(sorted_query, @associations)
75
+ query_helpers = parse_params(url_params)
76
+ filtered_query = PatternQueryHelper::Filtering.filter_active_record_query(active_record_call, query_helpers[:filters])
77
+ sorted_query = PatternQueryHelper::Sorting.sort_active_record_query(active_record_call, query_helpers[:sorting])
78
+ with_associations = PatternQueryHelper::Associations.load_associations(sorted_query, query_helpers[:associations])
79
79
  {
80
80
  data: with_associations
81
81
  }
82
82
  end
83
83
 
84
84
  def self.paginated_active_record_query(active_record_call, url_params)
85
- parse_params(url_params)
86
- filtered_query = PatternQueryHelper::Filtering.filter_active_record_query(active_record_call, @filtering)
87
- sorted_query = PatternQueryHelper::Sorting.sort_active_record_query(active_record_call, @sorting)
88
- paginated_query = PatternQueryHelper::Pagination.paginate_active_record_query(sorted_query, @pagination)
89
- with_associations = PatternQueryHelper::Associations.load_associations(paginated_query, @associations)
90
- pagination = PatternQueryHelper::Pagination.create_pagination_payload(sorted_query.count, @pagination)
85
+ query_helpers = parse_params(url_params)
86
+ filtered_query = PatternQueryHelper::Filtering.filter_active_record_query(active_record_call, query_helpers[:filters])
87
+ sorted_query = PatternQueryHelper::Sorting.sort_active_record_query(active_record_call, query_helpers[:sorting])
88
+ paginated_query = PatternQueryHelper::Pagination.paginate_active_record_query(sorted_query, query_helpers[:pagination])
89
+ with_associations = PatternQueryHelper::Associations.load_associations(paginated_query, query_helpers[:associations])
90
+ pagination = PatternQueryHelper::Pagination.create_pagination_payload(sorted_query.count, query_helpers[:pagination])
91
91
  {
92
92
  pagination: pagination,
93
93
  data: with_associations
@@ -99,16 +99,16 @@ module PatternQueryHelper
99
99
  end
100
100
 
101
101
  def self.parse_params(params)
102
- @filtering = PatternQueryHelper::Filtering.create_filters(params[:filter])
103
- @sorting = PatternQueryHelper::Sorting.parse_sorting_params(params)
104
- @associations = PatternQueryHelper::Associations.process_association_params(params)
105
- @pagination = PatternQueryHelper::Pagination.parse_pagination_params(params)
102
+ filtering = PatternQueryHelper::Filtering.create_filters(params)
103
+ sorting = PatternQueryHelper::Sorting.parse_sorting_params(params)
104
+ associations = PatternQueryHelper::Associations.process_association_params(params)
105
+ pagination = PatternQueryHelper::Pagination.parse_pagination_params(params)
106
106
 
107
107
  {
108
- filters: @filtering,
109
- sorting: @sorting,
110
- associations: @associations,
111
- pagination: @pagination
108
+ filters: filtering,
109
+ sorting: sorting,
110
+ associations: associations,
111
+ pagination: pagination
112
112
  }
113
113
  end
114
114
 
@@ -1,7 +1,7 @@
1
1
  module PatternQueryHelper
2
2
  class Filtering
3
- def self.create_filters(filters, column_map=nil, symbol_prefix="")
4
- filters ||= {}
3
+ def self.create_filters(params, column_map=nil, symbol_prefix="")
4
+ filters = params[:filter] || {}
5
5
  filter_string = "true = true"
6
6
  filter_params = {}
7
7
  filter_array = []
@@ -1,3 +1,3 @@
1
1
  module PatternQueryHelper
2
- VERSION = "0.1.2"
2
+ VERSION = "0.1.3"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pattern_query_helper
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Evan McDaniel
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-02-22 00:00:00.000000000 Z
11
+ date: 2019-02-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler