rad_core_rails 0.7.0 → 0.7.5

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: 9c80461bc2b08411eb1989bbda0e49d9cb47e73fbcd3b959c569742dd75f3342
4
- data.tar.gz: 7df243406dd934723cf34c117475b3384a0bd237486d390236ea0e9215671234
3
+ metadata.gz: 95f6475b2b10bb6d51c5b4ad3feb7ebe08404663230abcae5278e81babe5e189
4
+ data.tar.gz: 90bfdddfeda70290d119eaad3bb4cdd35afc593e04a1d7d7a0c71736567b6710
5
5
  SHA512:
6
- metadata.gz: 5e2f659480bbf9fe6b5eedbeb4a8c007c7877ee572709334a63441bbaeefd6f28488712010532eb7edb086028ad62714568b222a95f293ad387416917b05b098
7
- data.tar.gz: 9e3071cd56281bb7f2dcbd22a1c5ff0d106803233f6e537ea5c5f600ae0432bf18edfd99ea136a80aea6290114b6eefb76afbd7e7ba031c03ed104b041575ad0
6
+ metadata.gz: 5406cb277bf3591e979e14adb5aef5f92370483cd8dce83fb1cd78c333f0c57ebd9a9de3a586272c649738ee44fe5a32a2d7f08b3ab54b545c914366033e1bb9
7
+ data.tar.gz: 20950b080d702d04bde47999be305945643acdf50d078f9d0fe05a50108656ad648f453f652d248e4e0980b9df980f9e84cb0ae8b84b5b366597bffb4616f05b
data/.rspec CHANGED
@@ -1,3 +1,3 @@
1
- --format documentation
2
- --color
3
- --require spec_helper
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
@@ -1,6 +1,6 @@
1
- ---
2
- language: ruby
3
- cache: bundler
4
- rvm:
5
- - 2.4.5
1
+ ---
2
+ language: ruby
3
+ cache: bundler
4
+ rvm:
5
+ - 2.4.5
6
6
  - 2.7.0
@@ -1,74 +1,74 @@
1
- # Contributor Covenant Code of Conduct
2
-
3
- ## Our Pledge
4
-
5
- In the interest of fostering an open and welcoming environment, we as
6
- contributors and maintainers pledge to making participation in our project and
7
- our community a harassment-free experience for everyone, regardless of age, body
8
- size, disability, ethnicity, gender identity and expression, level of experience,
9
- nationality, personal appearance, race, religion, or sexual identity and
10
- orientation.
11
-
12
- ## Our Standards
13
-
14
- Examples of behavior that contributes to creating a positive environment
15
- include:
16
-
17
- * Using welcoming and inclusive language
18
- * Being respectful of differing viewpoints and experiences
19
- * Gracefully accepting constructive criticism
20
- * Focusing on what is best for the community
21
- * Showing empathy towards other community members
22
-
23
- Examples of unacceptable behavior by participants include:
24
-
25
- * The use of sexualized language or imagery and unwelcome sexual attention or
26
- advances
27
- * Trolling, insulting/derogatory comments, and personal or political attacks
28
- * Public or private harassment
29
- * Publishing others' private information, such as a physical or electronic
30
- address, without explicit permission
31
- * Other conduct which could reasonably be considered inappropriate in a
32
- professional setting
33
-
34
- ## Our Responsibilities
35
-
36
- Project maintainers are responsible for clarifying the standards of acceptable
37
- behavior and are expected to take appropriate and fair corrective action in
38
- response to any instances of unacceptable behavior.
39
-
40
- Project maintainers have the right and responsibility to remove, edit, or
41
- reject comments, commits, code, wiki edits, issues, and other contributions
42
- that are not aligned to this Code of Conduct, or to ban temporarily or
43
- permanently any contributor for other behaviors that they deem inappropriate,
44
- threatening, offensive, or harmful.
45
-
46
- ## Scope
47
-
48
- This Code of Conduct applies both within project spaces and in public spaces
49
- when an individual is representing the project or its community. Examples of
50
- representing a project or community include using an official project e-mail
51
- address, posting via an official social media account, or acting as an appointed
52
- representative at an online or offline event. Representation of a project may be
53
- further defined and clarified by project maintainers.
54
-
55
- ## Enforcement
56
-
57
- Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
- reported by contacting the project team at sancho.ck@gmail.com. All
59
- complaints will be reviewed and investigated and will result in a response that
60
- is deemed necessary and appropriate to the circumstances. The project team is
61
- obligated to maintain confidentiality with regard to the reporter of an incident.
62
- Further details of specific enforcement policies may be posted separately.
63
-
64
- Project maintainers who do not follow or enforce the Code of Conduct in good
65
- faith may face temporary or permanent repercussions as determined by other
66
- members of the project's leadership.
67
-
68
- ## Attribution
69
-
70
- This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
- available at [https://contributor-covenant.org/version/1/4][version]
72
-
73
- [homepage]: https://contributor-covenant.org
74
- [version]: https://contributor-covenant.org/version/1/4/
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at sancho.ck@gmail.com. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [https://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: https://contributor-covenant.org
74
+ [version]: https://contributor-covenant.org/version/1/4/
@@ -1,21 +1,21 @@
1
- The MIT License (MIT)
2
-
3
- Copyright (c) 2020 Oleksandr Poltavets
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in
13
- all copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
- THE SOFTWARE.
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2020 Oleksandr Poltavets
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -11,7 +11,7 @@ class <%= migration_class_name %> < ActiveRecord::Migration<%= migration_version
11
11
  end
12
12
 
13
13
  add_index :zip_codes, :zip, unique: true
14
- add_index :zip_codes, :latitude, unique: true
15
- add_index :zip_codes, :longitude, unique: true
14
+ add_index :zip_codes, :latitude
15
+ add_index :zip_codes, :longitude
16
16
  end
17
17
  end
@@ -40,66 +40,61 @@ module RadCoreRails
40
40
  args << arg
41
41
  end
42
42
  rescue NoMethodError
43
- raise NoMethodError.new("Filter with the name `#{filter[:key]}` doesn't exist.")
43
+ raise NoMethodError, "Filter with the name `#{filter[:key]}` doesn't exist."
44
44
  end
45
45
  end
46
46
  [query.reject(&:blank?).join(' AND '), args]
47
47
  end
48
48
 
49
- # def generate_search_clause(search)
50
- # and_args = []
51
- # or_args = []
52
- # if search.present? && searchable_columns.is_a?(Array)
53
- # # search_term_size = search.split(' ').length
54
- # and_terms = search.split(' ').select { |term| !term.include?('+') }
55
- # or_terms = search.split(' ').select { |term| term.include?('+') }
56
- # and_columns = []
57
- # or_columns = []
58
- # # just_ors = search_term_size == or_term_size
59
- # # operand = just_ors ? 'OR' : 'AND'
60
- # # search_terms = just_ors == true ? search.split(' ') : search.split(' ').select { |term| !term.include?('+') }
61
- # and_terms.each do |term|
62
- # columns = []
63
- # and_terms.each do |col|
64
- # and_columns.push("(LOWER(#{col}) ILIKE ?)")
65
- # and_args.push '%' + term.downcase.strip + '%'
66
- # end
67
- # or_terms.each do |col|
68
- # columns.push("(LOWER(#{col}) ILIKE ?)")
69
- # or_args.push '%' + term[1, term.length].downcase.strip + '%'
70
- # end
71
- # clause = if or_columns.empty?
72
- # '(' + and_columns.join(' OR ') + ')'
73
- # else
74
- # '(' + '(' + and_columns.join(' OR ') + ')' + 'AND' + '(' + or_columns.join(' OR ') + ')' + ')'
75
- # end
76
- # end
77
- # [clause, and_args + or_args]
78
- # else
79
- # ['', []]
80
- # end
81
- # end
82
-
83
- # @searchable_columns, is an array of column names that you can compare to your terms.
84
- #
85
49
  def generate_search_clause(search)
50
+ search_clause = ['', []]
51
+
86
52
  if search.present? && searchable_columns.is_a?(Array)
87
- # holds all of the sql from sanitized_and_terms
88
- and_args = []
89
- # holds all the table columns sql for all the AND terms
90
- and_clause = []
91
- # holds all of the sql from sanitized_or_terms
92
- or_args = []
93
- # holds all the table columns sql for all the OR terms
94
- or_clause = []
95
- # extract and terms, remove casing, and add ILIKE '%' comparisions
53
+ and_args = [] # SQL from sanitized_and_terms
54
+ excluded_args = [] # SQL from sanitized_excluded_terms
55
+ and_clause = [] # table columns SQL for all the AND terms
56
+ excluded_clause = [] # table columns SQL for all the AND NOT terms
57
+ or_args = [] # SQL from sanitized_or_terms
58
+ or_clause = [] # table columns SQL for all the OR terms
59
+
60
+ phrases_to_exclude = search.scan(/-"([^"]*)"/) # e.g. -"Phrase to exclude"
61
+ phrases_or = search.scan(/\+"([^"]*)"/) # e.g. +"Phrase for OR"
62
+
63
+ # remove excluded phrases from search if any
64
+ if phrases_to_exclude.any?
65
+ phrases_to_exclude.each {|phrase| search.gsub!('-"' + "#{phrase.first}" + '"', '')}
66
+ end
67
+
68
+ # remove 'or' phrases from search if any
69
+ if phrases_or.any?
70
+ phrases_or.each {|phrase| search.gsub!('+"' + "#{phrase.first}" + '"', '')}
71
+ end
72
+
73
+ # extract 'and' terms, remove casing, and add ILIKE '%' comparisons
96
74
  sanitized_and_terms = search.split(' ')
97
- .reject { |term| term.include?('+') }
75
+ .reject { |term| term.include?('+') || term.include?('-') }
98
76
  .map { |term| '%' + term.downcase.strip + '%' }
99
- # extract or terms, remove casing, and add ILIKE '%' comparisions
77
+
78
+ # extract 'or' terms, remove casing, and add ILIKE '%' comparisons
100
79
  sanitized_or_terms = search.split(' ')
101
80
  .select { |term| term.include?('+') }
102
81
  .map { |term| '%' + term[1, term.length].downcase.strip + '%' }
82
+
83
+ # add 'or' phrase terms, remove casing, and add ILIKE '%' comparisons
84
+ if phrases_or.any?
85
+ sanitized_or_terms += phrases_or.flatten.map{|phrase| '%' + phrase.downcase.strip + '%'}
86
+ end
87
+
88
+ # extract excluded terms, remove casing, and add NOT ILIKE '%' comparisons
89
+ sanitized_excluded_terms = search.split(' ')
90
+ .select { |term| term.include?('-') }
91
+ .map { |term| '%' + term[1, term.length].downcase.strip + '%' }
92
+
93
+ # add excluded phrase terms, remove casing, and add NOT ILIKE '%' comparisons
94
+ if phrases_to_exclude.any?
95
+ sanitized_excluded_terms += phrases_to_exclude.flatten.map{|phrase| '%' + phrase.downcase.strip + '%'}
96
+ end
97
+
103
98
  # loop through sanitized_and_terms to find all possible columns.
104
99
  sanitized_and_terms.each do |sanitized_term|
105
100
  columns = []
@@ -110,6 +105,16 @@ module RadCoreRails
110
105
  end
111
106
  and_clause.push '(' + columns.join(' OR ') + ')'
112
107
  end
108
+ # loop through sanitized_excluded_terms to find all possible columns.
109
+ sanitized_excluded_terms.each do |sanitized_term|
110
+ columns = []
111
+ # all possible columns where this should be searched
112
+ searchable_columns.each do |col|
113
+ columns.push("(LOWER(#{col}) NOT ILIKE ?)")
114
+ excluded_args.push sanitized_term
115
+ end
116
+ excluded_clause.push '(' + columns.join(' AND ') + ')'
117
+ end
113
118
  # loop through sanitized_or_terms to find all possible columns.
114
119
  sanitized_or_terms.each do |sanitized_term|
115
120
  columns = []
@@ -120,18 +125,48 @@ module RadCoreRails
120
125
  end
121
126
  or_clause.push '(' + columns.join(' OR ') + ')'
122
127
  end
128
+
129
+ if or_clause.empty? && and_clause.empty? && excluded_clause.empty?
130
+ return ['', []]
131
+ end
132
+
133
+ if or_clause.empty? && excluded_clause.empty?
134
+ return ['(' + and_clause.join(' AND ') + ')', and_args]
135
+ end
136
+
137
+ if and_clause.empty? && excluded_clause.empty?
138
+ return ['(' + or_clause.join(' OR ') + ')', or_args]
139
+ end
140
+
123
141
  if or_clause.empty? && and_clause.empty?
124
- ['', []]
125
- elsif or_clause.empty?
126
- ['(' + and_clause.join(' AND ') + ')', and_args]
127
- elsif and_clause.empty?
128
- ['(' + or_clause.join(' OR ') + ')', or_args]
129
- else
130
- ['((' + and_clause.join(' AND ') + ') AND (' + or_clause.join(' OR ') + '))', and_args + or_args]
142
+ return ['(' + excluded_clause.join(' AND ') + ')', excluded_args]
131
143
  end
132
- else
133
- ['', []]
144
+
145
+ if or_clause.empty?
146
+ return ['((' + and_clause.join(' AND ') + ') AND (' + excluded_clause.join(' AND ') + '))', and_args + excluded_args]
147
+ end
148
+
149
+ if and_clause.empty?
150
+ return ['((' + or_clause.join(' OR ') + ') AND (' + excluded_clause.join(' AND ') + '))', or_args + excluded_args]
151
+ end
152
+
153
+ if excluded_clause.empty?
154
+ return ['((' + and_clause.join(' AND ') + ') AND (' + or_clause.join(' OR ') + '))', and_args + or_args]
155
+ end
156
+
157
+ search_clause = [
158
+ '((' +
159
+ and_clause.join(' AND ') +
160
+ ') AND (' +
161
+ or_clause.join(' OR ') +
162
+ ') AND (' +
163
+ excluded_clause.join(' AND ') +
164
+ '))',
165
+ and_args + or_args + excluded_args
166
+ ]
134
167
  end
168
+
169
+ search_clause
135
170
  end
136
171
 
137
172
  # Generate Boolean clause
@@ -164,8 +199,13 @@ module RadCoreRails
164
199
  end
165
200
 
166
201
  def generate_array_clause(column_name, filter)
167
- str = "(#{column_name} && ARRAY[?])"
168
- args = [filter[:values]]
202
+ if filter[:option] == '!='
203
+ str = "(SELECT NOT(#{column_name}::text[] && ARRAY[?]))"
204
+ args = [filter[:values]]
205
+ else
206
+ str = "(SELECT (#{column_name}::text[] && ARRAY[?]))"
207
+ args = [filter[:values]]
208
+ end
169
209
 
170
210
  [str, args]
171
211
  end
@@ -254,6 +294,7 @@ module RadCoreRails
254
294
 
255
295
  def handle_filterable(filters_data)
256
296
  return nil if filters_data.empty?
297
+
257
298
  @zip_code_class = filters_data.delete(:zip_code_class)
258
299
 
259
300
  result = {}
@@ -270,6 +311,7 @@ module RadCoreRails
270
311
 
271
312
  def zip_code_class
272
313
  return RadCoreRails::ZipCode unless @zip_code_class
314
+
273
315
  @zip_code_class.to_s.constantize
274
316
  end
275
317
  end