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 +4 -4
- data/.travis.yml +0 -1
- data/Gemfile.lock +32 -32
- data/README.md +2 -0
- data/lib/pattern_query_helper/sorting.rb +3 -1
- data/lib/pattern_query_helper/version.rb +1 -1
- data/lib/pattern_query_helper.rb +20 -16
- data/pattern_query_helper.gemspec +3 -3
- metadata +14 -14
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f0cd0ab9dafb896354a15f72a94a08f7ed138aa4
|
4
|
+
data.tar.gz: 7d8a6af8fcaea92089dde58d8a0a44952ecd7c7e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f1351d92b0aaaa74ef26d8db9f155f9875920326d830ae5cefbcd5c14caec38436993d6663a9088332b4fdfb1dfdac0bbac7f5947f60c3fff09c22170f118271
|
7
|
+
data.tar.gz: dbf25ee9fbf6b7ae8e59573cbf3c29bda4e29e0a68c4da221cc1ca084b5d3b7af22d61270fd284c01f52af4efdd7c6ad2b0b135864b1afefaaa7a732c738aa9d
|
data/.travis.yml
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,59 +1,59 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
pattern_query_helper (0.2.
|
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.
|
12
|
-
activesupport (= 5.
|
11
|
+
actionview (5.2.2)
|
12
|
+
activesupport (= 5.2.2)
|
13
13
|
builder (~> 3.1)
|
14
|
-
|
14
|
+
erubi (~> 1.4)
|
15
15
|
rails-dom-testing (~> 2.0)
|
16
16
|
rails-html-sanitizer (~> 1.0, >= 1.0.3)
|
17
|
-
activemodel (5.
|
18
|
-
activesupport (= 5.
|
19
|
-
activerecord (5.
|
20
|
-
activemodel (= 5.
|
21
|
-
activesupport (= 5.
|
22
|
-
arel (
|
23
|
-
activesupport (5.
|
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 (
|
28
|
+
arel (9.0.0)
|
29
29
|
builder (3.2.3)
|
30
|
-
concurrent-ruby (1.1.
|
30
|
+
concurrent-ruby (1.1.4)
|
31
31
|
crass (1.0.4)
|
32
32
|
diff-lcs (1.3)
|
33
|
-
|
34
|
-
faker (1.
|
35
|
-
i18n (
|
36
|
-
i18n (
|
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.
|
38
|
+
kaminari (1.1.1)
|
39
39
|
activesupport (>= 4.1.0)
|
40
|
-
kaminari-actionview (= 1.1.
|
41
|
-
kaminari-activerecord (= 1.1.
|
42
|
-
kaminari-core (= 1.1.
|
43
|
-
kaminari-actionview (1.1.
|
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.
|
46
|
-
kaminari-activerecord (1.1.
|
45
|
+
kaminari-core (= 1.1.1)
|
46
|
+
kaminari-activerecord (1.1.1)
|
47
47
|
activerecord
|
48
|
-
kaminari-core (= 1.1.
|
49
|
-
kaminari-core (1.1.
|
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.
|
53
|
+
mini_portile2 (2.4.0)
|
54
54
|
minitest (5.11.3)
|
55
|
-
nokogiri (1.
|
56
|
-
mini_portile2 (~> 2.
|
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"
|
data/lib/pattern_query_helper.rb
CHANGED
@@ -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(
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
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.
|
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-
|
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:
|
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:
|
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:
|
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:
|
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:
|
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:
|
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:
|