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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: bd01bd1bb2d9d6a147901d752704a95fede83e2e36594a99d6c88e1c8785661b
4
- data.tar.gz: 49598f17de968766008e4a8ecec0abf77f69221afe137c5be578c7fbdb7e3478
3
+ metadata.gz: 9453dd7bcd81b06616c716a74a14ae740d6173adee4cfc437f471f6d13c5b2b4
4
+ data.tar.gz: b7733e5a0ddcf2863881e0684a89c58e71d3aa7b23bf61d05fc60e605ba5d971
5
5
  SHA512:
6
- metadata.gz: c5c80726313dad975cc05bf938c144df0e5ccfa10eafd3d3cbaec8f5045e4cc033ea386c7e045f0a08b6a4d4703d70b8a8383db1b0764577ba1cb6d08cf9eb8f
7
- data.tar.gz: 853228f2fffbdc90121f416ba8bdddb76157e1bab720e424947b5da28709168a10ef78331ba9820b5145dfb9fc27280223de1062a01f883613ed388d4afdbec5
6
+ metadata.gz: 13701a60b84af168b394e3dce1d997017b86a6643a893693dcf37305094776705d4420eba30916ec884e387449ed4cf4e696ddc8749cdf81dd1986f40fabe304
7
+ data.tar.gz: cdbb6f829d15c0c8af6b7b0e029f51a464bbe3b61dc62fd42fee23d939ba144a99a89c555c414b8c44b13c981ccf206358ef35c48e18722c9f9d93a9f97adeb0
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- seek_party (0.0.3)
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.5)
55
- crass (1.0.5)
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.7.0)
61
+ i18n (1.8.2)
62
62
  concurrent-ruby (~> 1.0)
63
- json (2.3.0)
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.9.2)
72
- mimemagic (0.3.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.13.0)
74
+ minitest (5.14.1)
76
75
  nio4r (2.5.2)
77
- nokogiri (1.10.7)
76
+ nokogiri (1.10.9)
78
77
  mini_portile2 (~> 2.4.0)
79
- rack (2.0.8)
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.17.1)
127
+ simplecov (0.18.5)
129
128
  docile (~> 1.1)
130
- json (>= 1.8, < 3)
131
- simplecov-html (~> 0.10.0)
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.1)
138
+ sqlite3 (1.4.2)
141
139
  thor (1.0.1)
142
140
  thread_safe (0.3.6)
143
- tzinfo (1.2.5)
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
+ [![Build Status](https://travis-ci.org/caws/seek_party.svg?branch=master)](https://travis-ci.org/caws/seek_party)
4
+ [![Maintainability](https://api.codeclimate.com/v1/badges/a05e479c6f535645d307/maintainability)](https://codeclimate.com/github/caws/seek_party/maintainability)
5
+ [![Test Coverage](https://api.codeclimate.com/v1/badges/a05e479c6f535645d307/test_coverage)](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.3'
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 '%sugoi%' AND LOWER(CAST(users.name AS TEXT)) = 'bilbo' OR LOWER(CAST(users.email AS TEXT)) LIKE '%sugoi%' AND LOWER(CAST(users.name AS TEXT)) = 'bilbo')
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
@@ -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
- final_query = ''
19
- @queries.each do |_key, value|
20
- next unless value
18
+ return if @queries.blank?
21
19
 
22
- final_query << if value == @queries[@queries.keys.first]
23
- value
24
- else
25
- @params[:search].present? ? " OR #{value}" : " AND #{value}"
26
- end
27
- end
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: pluralize_and_snake_case_class_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 pluralize_and_snake_case_class_name
49
- @inspected_class.name.pluralize.underscore
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 |key, value|
43
- @inspected_class = @inspected_class.method(key).call(value)
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
- @sp_query.set_attribute_query(attribute, "#{cast_column_name} LIKE "\
36
- "'%#{params[:search].downcase}%'")
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
- "'#{@params[attribute.to_sym].to_s.downcase}'"
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?
@@ -1,3 +1,3 @@
1
1
  module SeekParty
2
- VERSION = '0.0.3'.freeze
2
+ VERSION = '0.0.9'.freeze
3
3
  end
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.3
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: 2019-12-23 00:00:00.000000000 Z
11
+ date: 2020-06-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler