pattern_query_helper 0.2.0 → 0.2.1

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: 65460f1546e868997cf4f1b0d049ee2d16f68ff4
4
- data.tar.gz: 347f43fb24fad0aed12bfd4c5e3c901edc5b5b87
3
+ metadata.gz: f0cd0ab9dafb896354a15f72a94a08f7ed138aa4
4
+ data.tar.gz: 7d8a6af8fcaea92089dde58d8a0a44952ecd7c7e
5
5
  SHA512:
6
- metadata.gz: 8db937be84711841bd756d37f43021ad0e73541bcc9f16401641d03f1fbb0429c505c5e6668d0a4e7eb80128246c69734aab59b3b6f977e5811f2404eda7a78b
7
- data.tar.gz: f198e72b5325b64221fc4105da3259f8e6ed2127b5fd625549f0b13fed206bccb850cbfa049d9aceb6eb9b32723bb4a5125a2d8b7a88b416c5188f4001e20f67
6
+ metadata.gz: f1351d92b0aaaa74ef26d8db9f155f9875920326d830ae5cefbcd5c14caec38436993d6663a9088332b4fdfb1dfdac0bbac7f5947f60c3fff09c22170f118271
7
+ data.tar.gz: dbf25ee9fbf6b7ae8e59573cbf3c29bda4e29e0a68c4da221cc1ca084b5d3b7af22d61270fd284c01f52af4efdd7c6ad2b0b135864b1afefaaa7a732c738aa9d
data/.travis.yml CHANGED
@@ -1,4 +1,3 @@
1
- ---
2
1
  sudo: false
3
2
  language: ruby
4
3
  cache: bundler
data/Gemfile.lock CHANGED
@@ -1,59 +1,59 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- pattern_query_helper (0.2.0)
4
+ pattern_query_helper (0.2.1)
5
5
  activerecord (~> 5.0)
6
- kaminari
6
+ kaminari (~> 1.1.1)
7
7
 
8
8
  GEM
9
9
  remote: https://rubygems.org/
10
10
  specs:
11
- actionview (5.0.7)
12
- activesupport (= 5.0.7)
11
+ actionview (5.2.2)
12
+ activesupport (= 5.2.2)
13
13
  builder (~> 3.1)
14
- erubis (~> 2.7.0)
14
+ erubi (~> 1.4)
15
15
  rails-dom-testing (~> 2.0)
16
16
  rails-html-sanitizer (~> 1.0, >= 1.0.3)
17
- activemodel (5.0.7)
18
- activesupport (= 5.0.7)
19
- activerecord (5.0.7)
20
- activemodel (= 5.0.7)
21
- activesupport (= 5.0.7)
22
- arel (~> 7.0)
23
- activesupport (5.0.7)
17
+ activemodel (5.2.2)
18
+ activesupport (= 5.2.2)
19
+ activerecord (5.2.2)
20
+ activemodel (= 5.2.2)
21
+ activesupport (= 5.2.2)
22
+ arel (>= 9.0)
23
+ activesupport (5.2.2)
24
24
  concurrent-ruby (~> 1.0, >= 1.0.2)
25
25
  i18n (>= 0.7, < 2)
26
26
  minitest (~> 5.1)
27
27
  tzinfo (~> 1.1)
28
- arel (7.1.4)
28
+ arel (9.0.0)
29
29
  builder (3.2.3)
30
- concurrent-ruby (1.1.3)
30
+ concurrent-ruby (1.1.4)
31
31
  crass (1.0.4)
32
32
  diff-lcs (1.3)
33
- erubis (2.7.0)
34
- faker (1.8.4)
35
- i18n (~> 0.5)
36
- i18n (0.9.3)
33
+ erubi (1.8.0)
34
+ faker (1.9.3)
35
+ i18n (>= 0.7)
36
+ i18n (1.6.0)
37
37
  concurrent-ruby (~> 1.0)
38
- kaminari (1.1.0)
38
+ kaminari (1.1.1)
39
39
  activesupport (>= 4.1.0)
40
- kaminari-actionview (= 1.1.0)
41
- kaminari-activerecord (= 1.1.0)
42
- kaminari-core (= 1.1.0)
43
- kaminari-actionview (1.1.0)
40
+ kaminari-actionview (= 1.1.1)
41
+ kaminari-activerecord (= 1.1.1)
42
+ kaminari-core (= 1.1.1)
43
+ kaminari-actionview (1.1.1)
44
44
  actionview
45
- kaminari-core (= 1.1.0)
46
- kaminari-activerecord (1.1.0)
45
+ kaminari-core (= 1.1.1)
46
+ kaminari-activerecord (1.1.1)
47
47
  activerecord
48
- kaminari-core (= 1.1.0)
49
- kaminari-core (1.1.0)
48
+ kaminari-core (= 1.1.1)
49
+ kaminari-core (1.1.1)
50
50
  loofah (2.2.3)
51
51
  crass (~> 1.0.2)
52
52
  nokogiri (>= 1.5.9)
53
- mini_portile2 (2.3.0)
53
+ mini_portile2 (2.4.0)
54
54
  minitest (5.11.3)
55
- nokogiri (1.8.5)
56
- mini_portile2 (~> 2.3.0)
55
+ nokogiri (1.10.1)
56
+ mini_portile2 (~> 2.4.0)
57
57
  rails-dom-testing (2.0.3)
58
58
  activesupport (>= 4.2.0)
59
59
  nokogiri (>= 1.6)
@@ -83,11 +83,11 @@ PLATFORMS
83
83
 
84
84
  DEPENDENCIES
85
85
  bundler (~> 1.16)
86
- faker
86
+ faker (~> 1.9.3)
87
87
  pattern_query_helper!
88
88
  rake (~> 10.0)
89
89
  rspec (~> 3.0)
90
- sqlite3
90
+ sqlite3 (~> 1.3.6)
91
91
 
92
92
  BUNDLED WITH
93
93
  1.16.6
data/README.md CHANGED
@@ -1,4 +1,6 @@
1
1
  # PatternQueryHelper
2
+ [![TravisCI](https://travis-ci.org/iserve-products/pattern_query_helper.svg?branch=master)](https://travis-ci.org/iserve-products/pattern_query_helper)
3
+ [![Gem Version](https://badge.fury.io/rb/pattern_query_helper.svg)](https://badge.fury.io/rb/pattern_query_helper)
2
4
 
3
5
  Ruby Gem developed and used at Pattern to paginate, sort, filter, and include associations on sql and active record queries.
4
6
 
@@ -1,6 +1,6 @@
1
1
  module PatternQueryHelper
2
2
  class Sorting
3
- def self.parse_sorting_params(sort)
3
+ def self.parse_sorting_params(sort, valid_columns)
4
4
  sort_sql = []
5
5
  if sort
6
6
  sorts = sort.split(",")
@@ -9,6 +9,8 @@ module PatternQueryHelper
9
9
  direction = sort.split(":")[1]
10
10
  modifier = sort.split(":")[2]
11
11
 
12
+ raise ArgumentError.new("Sorting not allowed on column '#{column}'") unless valid_columns.include? column
13
+
12
14
  if direction == "desc"
13
15
  case PatternQueryHelper.active_record_adapter
14
16
  when "sqlite3"
@@ -1,3 +1,3 @@
1
1
  module PatternQueryHelper
2
- VERSION = "0.2.0"
2
+ VERSION = "0.2.1"
3
3
  end
@@ -7,24 +7,24 @@ require "pattern_query_helper/sql"
7
7
 
8
8
  module PatternQueryHelper
9
9
 
10
- def self.run_sql_query(model, query, query_params, query_helpers, single_record=false)
10
+ def self.run_sql_query(model, query, query_params, query_helpers, valid_columns=[], single_record=false)
11
11
  if single_record
12
- single_record_sql_query(model, query, query_params, query_helpers)
12
+ single_record_sql_query(model, query, query_params, query_helpers, valid_columns)
13
13
  elsif query_helpers[:per_page] || query_helpers[:page]
14
- paginated_sql_query(model, query, query_params, query_helpers)
14
+ paginated_sql_query(model, query, query_params, query_helpers, valid_columns)
15
15
  else
16
- sql_query(model, query, query_params, query_helpers)
16
+ sql_query(model, query, query_params, query_helpers, valid_columns)
17
17
  end
18
18
  end
19
19
 
20
- def self.run_active_record_query(active_record_call, query_helpers, single_record=false)
20
+ def self.run_active_record_query(active_record_call, query_helpers, valid_columns=[], single_record=false)
21
21
  run_sql_query(active_record_call.model, active_record_call.to_sql, {}, query_helpers, single_record)
22
22
  end
23
23
 
24
24
  private
25
25
 
26
- def self.paginated_sql_query(model, query, query_params, query_helpers)
27
- query_helpers = parse_helpers(query_helpers)
26
+ def self.paginated_sql_query(model, query, query_params, query_helpers, valid_columns)
27
+ query_helpers = parse_helpers(query_helpers, valid_columns)
28
28
 
29
29
  query_config = {
30
30
  model: model,
@@ -48,8 +48,8 @@ module PatternQueryHelper
48
48
  }
49
49
  end
50
50
 
51
- def self.sql_query(model, query, query_params, query_helpers)
52
- query_helpers = parse_helpers(query_helpers)
51
+ def self.sql_query(model, query, query_params, query_helpers, valid_columns)
52
+ query_helpers = parse_helpers(query_helpers, valid_columns)
53
53
 
54
54
  query_config = {
55
55
  model: model,
@@ -68,8 +68,8 @@ module PatternQueryHelper
68
68
  }
69
69
  end
70
70
 
71
- def self.single_record_sql_query(model, query, query_params, query_helpers)
72
- query_helpers = parse_helpers(query_helpers)
71
+ def self.single_record_sql_query(model, query, query_params, query_helpers, valid_columns)
72
+ query_helpers = parse_helpers(query_helpers, valid_columns)
73
73
 
74
74
  query_config = {
75
75
  model: model,
@@ -88,11 +88,15 @@ module PatternQueryHelper
88
88
  }
89
89
  end
90
90
 
91
- def self.parse_helpers(params)
92
- filtering = PatternQueryHelper::Filtering.create_filters(params[:filter])
93
- sorting = PatternQueryHelper::Sorting.parse_sorting_params(params[:sort])
94
- associations = PatternQueryHelper::Associations.process_association_params(params[:include])
95
- pagination = PatternQueryHelper::Pagination.parse_pagination_params(params[:page], params[:per_page])
91
+ def self.parse_helpers(query_helpers, valid_columns)
92
+ valid_columns_map = {}
93
+ valid_columns.each do |c|
94
+ valid_columns_map["#{c}"] = c
95
+ end
96
+ filtering = PatternQueryHelper::Filtering.create_filters(query_helpers[:filter], valid_columns_map)
97
+ sorting = PatternQueryHelper::Sorting.parse_sorting_params(query_helpers[:sort], valid_columns)
98
+ associations = PatternQueryHelper::Associations.process_association_params(query_helpers[:include])
99
+ pagination = PatternQueryHelper::Pagination.parse_pagination_params(query_helpers[:page], query_helpers[:per_page])
96
100
 
97
101
  {
98
102
  filters: filtering,
@@ -39,9 +39,9 @@ Gem::Specification.new do |spec|
39
39
  spec.add_development_dependency "bundler", "~> 1.16"
40
40
  spec.add_development_dependency "rake", "~> 10.0"
41
41
  spec.add_development_dependency "rspec", "~> 3.0"
42
- spec.add_development_dependency "sqlite3"
43
- spec.add_development_dependency "faker"
42
+ spec.add_development_dependency "sqlite3", "~> 1.3.6"
43
+ spec.add_development_dependency "faker", "~> 1.9.3"
44
44
 
45
45
  spec.add_dependency "activerecord", "~> 5.0"
46
- spec.add_dependency "kaminari"
46
+ spec.add_dependency "kaminari", "~> 1.1.1"
47
47
  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.2.0
4
+ version: 0.2.1
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-03-05 00:00:00.000000000 Z
11
+ date: 2019-03-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -56,30 +56,30 @@ dependencies:
56
56
  name: sqlite3
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - ">="
59
+ - - "~>"
60
60
  - !ruby/object:Gem::Version
61
- version: '0'
61
+ version: 1.3.6
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - ">="
66
+ - - "~>"
67
67
  - !ruby/object:Gem::Version
68
- version: '0'
68
+ version: 1.3.6
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: faker
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
- - - ">="
73
+ - - "~>"
74
74
  - !ruby/object:Gem::Version
75
- version: '0'
75
+ version: 1.9.3
76
76
  type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
- - - ">="
80
+ - - "~>"
81
81
  - !ruby/object:Gem::Version
82
- version: '0'
82
+ version: 1.9.3
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: activerecord
85
85
  requirement: !ruby/object:Gem::Requirement
@@ -98,16 +98,16 @@ dependencies:
98
98
  name: kaminari
99
99
  requirement: !ruby/object:Gem::Requirement
100
100
  requirements:
101
- - - ">="
101
+ - - "~>"
102
102
  - !ruby/object:Gem::Version
103
- version: '0'
103
+ version: 1.1.1
104
104
  type: :runtime
105
105
  prerelease: false
106
106
  version_requirements: !ruby/object:Gem::Requirement
107
107
  requirements:
108
- - - ">="
108
+ - - "~>"
109
109
  - !ruby/object:Gem::Version
110
- version: '0'
110
+ version: 1.1.1
111
111
  description: Ruby gem developed to help with pagination, filtering, sorting, and including
112
112
  associations on both active record queries and custom sql queries
113
113
  email: