seek_party 0.0.3 → 0.0.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Gemfile.lock +15 -17
- data/README.md +6 -4
- data/lib/seek_party.rb +0 -3
- data/lib/seek_party/models/sp_query.rb +10 -11
- data/lib/seek_party/seek_party_attribute.rb +3 -3
- data/lib/seek_party/seek_party_engine.rb +16 -2
- data/lib/seek_party/seek_party_query_builder.rb +7 -4
- data/lib/seek_party/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9453dd7bcd81b06616c716a74a14ae740d6173adee4cfc437f471f6d13c5b2b4
|
4
|
+
data.tar.gz: b7733e5a0ddcf2863881e0684a89c58e71d3aa7b23bf61d05fc60e605ba5d971
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 13701a60b84af168b394e3dce1d997017b86a6643a893693dcf37305094776705d4420eba30916ec884e387449ed4cf4e696ddc8749cdf81dd1986f40fabe304
|
7
|
+
data.tar.gz: cdbb6f829d15c0c8af6b7b0e029f51a464bbe3b61dc62fd42fee23d939ba144a99a89c555c414b8c44b13c981ccf206358ef35c48e18722c9f9d93a9f97adeb0
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
seek_party (0.0.
|
4
|
+
seek_party (0.0.8)
|
5
5
|
|
6
6
|
GEM
|
7
7
|
remote: https://rubygems.org/
|
@@ -51,32 +51,31 @@ GEM
|
|
51
51
|
builder (3.2.4)
|
52
52
|
codeclimate-test-reporter (1.0.7)
|
53
53
|
simplecov
|
54
|
-
concurrent-ruby (1.1.
|
55
|
-
crass (1.0.
|
54
|
+
concurrent-ruby (1.1.6)
|
55
|
+
crass (1.0.6)
|
56
56
|
diff-lcs (1.3)
|
57
57
|
docile (1.3.2)
|
58
58
|
erubi (1.9.0)
|
59
59
|
globalid (0.4.2)
|
60
60
|
activesupport (>= 4.2.0)
|
61
|
-
i18n (1.
|
61
|
+
i18n (1.8.2)
|
62
62
|
concurrent-ruby (~> 1.0)
|
63
|
-
|
64
|
-
loofah (2.4.0)
|
63
|
+
loofah (2.5.0)
|
65
64
|
crass (~> 1.0.2)
|
66
65
|
nokogiri (>= 1.5.9)
|
67
66
|
mail (2.7.1)
|
68
67
|
mini_mime (>= 0.1.1)
|
69
68
|
marcel (0.3.3)
|
70
69
|
mimemagic (~> 0.3.2)
|
71
|
-
method_source (0.
|
72
|
-
mimemagic (0.3.
|
70
|
+
method_source (1.0.0)
|
71
|
+
mimemagic (0.3.5)
|
73
72
|
mini_mime (1.0.2)
|
74
73
|
mini_portile2 (2.4.0)
|
75
|
-
minitest (5.
|
74
|
+
minitest (5.14.1)
|
76
75
|
nio4r (2.5.2)
|
77
|
-
nokogiri (1.10.
|
76
|
+
nokogiri (1.10.9)
|
78
77
|
mini_portile2 (~> 2.4.0)
|
79
|
-
rack (2.
|
78
|
+
rack (2.2.2)
|
80
79
|
rack-test (1.1.0)
|
81
80
|
rack (>= 1.0, < 3)
|
82
81
|
rails (5.2.4.1)
|
@@ -125,11 +124,10 @@ GEM
|
|
125
124
|
rspec-mocks (~> 3.8.0)
|
126
125
|
rspec-support (~> 3.8.0)
|
127
126
|
rspec-support (3.8.2)
|
128
|
-
simplecov (0.
|
127
|
+
simplecov (0.18.5)
|
129
128
|
docile (~> 1.1)
|
130
|
-
|
131
|
-
|
132
|
-
simplecov-html (0.10.2)
|
129
|
+
simplecov-html (~> 0.11)
|
130
|
+
simplecov-html (0.12.2)
|
133
131
|
sprockets (4.0.0)
|
134
132
|
concurrent-ruby (~> 1.0)
|
135
133
|
rack (> 1, < 3)
|
@@ -137,10 +135,10 @@ GEM
|
|
137
135
|
actionpack (>= 4.0)
|
138
136
|
activesupport (>= 4.0)
|
139
137
|
sprockets (>= 3.0.0)
|
140
|
-
sqlite3 (1.4.
|
138
|
+
sqlite3 (1.4.2)
|
141
139
|
thor (1.0.1)
|
142
140
|
thread_safe (0.3.6)
|
143
|
-
tzinfo (1.2.
|
141
|
+
tzinfo (1.2.7)
|
144
142
|
thread_safe (~> 0.1)
|
145
143
|
websocket-driver (0.7.1)
|
146
144
|
websocket-extensions (>= 0.1.0)
|
data/README.md
CHANGED
@@ -1,5 +1,9 @@
|
|
1
1
|
# SeekParty - Searches made easy
|
2
2
|
|
3
|
+
[](https://travis-ci.org/caws/seek_party)
|
4
|
+
[](https://codeclimate.com/github/caws/seek_party/maintainability)
|
5
|
+
[](https://codeclimate.com/github/caws/seek_party/test_coverage)
|
6
|
+
|
3
7
|
### What is this?
|
4
8
|
|
5
9
|
Have you ever had to write a search functionality for a web application and found yourself
|
@@ -33,8 +37,6 @@ Below is what's currently doable:
|
|
33
37
|
PS: The DEFAULT_BLACK_LIST contains the attributes :id, :created_at and :updated_at. You can pass your own
|
34
38
|
DEFAULT_BLACK_LIST when calling the #search method from your model, but I recommend using the WHITE_LIST,
|
35
39
|
as SeekParty will then only generate queries using the column names present there.
|
36
|
-
You should also keep in mind that when building the queries, seek_party tries to pluralize your table name in order to refer to the table
|
37
|
-
columns by their full name (ex: 'your_table.your_column_name').
|
38
40
|
|
39
41
|
## Getting started
|
40
42
|
|
@@ -43,7 +45,7 @@ PS: The DEFAULT_BLACK_LIST contains the attributes :id, :created_at and :updated
|
|
43
45
|
Add the following to your Gemfile
|
44
46
|
|
45
47
|
``` ruby
|
46
|
-
gem 'seek_party', '~> 0.0.
|
48
|
+
gem 'seek_party', '~> 0.0.7'
|
47
49
|
```
|
48
50
|
Then run:
|
49
51
|
|
@@ -134,7 +136,7 @@ User.search(params: params)
|
|
134
136
|
And this would result in the following query being produced:
|
135
137
|
|
136
138
|
``` sql
|
137
|
-
SELECT "users".* FROM "users" WHERE (LOWER(CAST(users.name AS TEXT)) LIKE '%
|
139
|
+
SELECT "users".* FROM "users" WHERE (LOWER(CAST(users.name AS TEXT)) LIKE '%bilbo@theshire.com%' AND LOWER(CAST(users.name AS TEXT)) = 'bilbo' OR LOWER(CAST(users.email AS TEXT)) LIKE '%bilbo@theshire.com%' AND LOWER(CAST(users.name AS TEXT)) = 'bilbo')
|
138
140
|
```
|
139
141
|
|
140
142
|
### TO DO
|
data/lib/seek_party.rb
CHANGED
@@ -14,9 +14,6 @@ module SeekParty
|
|
14
14
|
black_list: DEFAULT_BLACK_LIST,
|
15
15
|
white_list: nil,
|
16
16
|
scopes: [])
|
17
|
-
# If there are params to work with, use SeekParty.
|
18
|
-
# Otherwise, just return an empty instance of ActiveRecord_Relation.
|
19
|
-
return none if params.empty?
|
20
17
|
|
21
18
|
SeekPartyEngine
|
22
19
|
.new(self,
|
@@ -15,18 +15,17 @@ class SPQuery
|
|
15
15
|
end
|
16
16
|
|
17
17
|
def build_final_query
|
18
|
-
|
19
|
-
@queries.each do |_key, value|
|
20
|
-
next unless value
|
18
|
+
return if @queries.blank?
|
21
19
|
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
final_query
|
20
|
+
@queries.map { |key, value|
|
21
|
+
if key == @queries.keys.first
|
22
|
+
value
|
23
|
+
else
|
24
|
+
or_and(value)
|
25
|
+
end }.sum
|
30
26
|
end
|
31
27
|
|
28
|
+
def or_and(value)
|
29
|
+
@params[:search].present? ? " OR #{value}" : " AND #{value}"
|
30
|
+
end
|
32
31
|
end
|
@@ -23,7 +23,7 @@ module SeekParty
|
|
23
23
|
def check_attributes(another_model)
|
24
24
|
return nil if another_model.nil?
|
25
25
|
|
26
|
-
sp_attribute = SPAttribute.new(table_name:
|
26
|
+
sp_attribute = SPAttribute.new(table_name: get_table_name)
|
27
27
|
|
28
28
|
another_model.attributes.keys.each do |attribute|
|
29
29
|
next unless another_model.has_attribute? attribute
|
@@ -45,8 +45,8 @@ module SeekParty
|
|
45
45
|
@black_list.include? attribute_name
|
46
46
|
end
|
47
47
|
|
48
|
-
def
|
49
|
-
@inspected_class.
|
48
|
+
def get_table_name
|
49
|
+
@inspected_class.table_name.underscore
|
50
50
|
end
|
51
51
|
end
|
52
52
|
end
|
@@ -39,8 +39,22 @@ module SeekParty
|
|
39
39
|
# else, as the returned object from run_search is an
|
40
40
|
# ActiveRecord_Relation object that would accept
|
41
41
|
# method chaining
|
42
|
-
@scopes.each do |
|
43
|
-
|
42
|
+
@scopes.each do |scope|
|
43
|
+
if scope.respond_to?(:keys)
|
44
|
+
scope.keys.each do |key|
|
45
|
+
scope_call(key, scope[key])
|
46
|
+
end
|
47
|
+
else
|
48
|
+
scope_call(scope, nil)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
def scope_call(key, value)
|
54
|
+
if value.present?
|
55
|
+
@inspected_class = @inspected_class.method(key).call(*value)
|
56
|
+
else
|
57
|
+
@inspected_class = @inspected_class.method(key).call
|
44
58
|
end
|
45
59
|
end
|
46
60
|
end
|
@@ -32,8 +32,8 @@ module SeekParty
|
|
32
32
|
if params[:search].present?
|
33
33
|
full_column_name = spattribute.get_full_column_name(attribute)
|
34
34
|
cast_column_name = cast_according_to_adapter(full_column_name)
|
35
|
-
|
36
|
-
|
35
|
+
sanitized_sql = sanitize_sql(["#{cast_column_name} LIKE ?", "%#{params[:search].downcase}%"])
|
36
|
+
@sp_query.set_attribute_query(attribute, sanitized_sql)
|
37
37
|
end
|
38
38
|
|
39
39
|
# If there are other params being used other than :search
|
@@ -58,8 +58,11 @@ module SeekParty
|
|
58
58
|
end
|
59
59
|
|
60
60
|
def build_equals_query(attribute)
|
61
|
-
"#{cast_according_to_adapter(attribute)} = "
|
62
|
-
|
61
|
+
sanitize_sql(["#{cast_according_to_adapter(attribute)} = ?", @params[attribute.to_sym].to_s.downcase])
|
62
|
+
end
|
63
|
+
|
64
|
+
def sanitize_sql(sql_array)
|
65
|
+
ActiveRecord::Base::sanitize_sql_array(sql_array)
|
63
66
|
end
|
64
67
|
|
65
68
|
def db_sqlite3?
|
data/lib/seek_party/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: seek_party
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.9
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Charles Washington
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-06-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|