rad_core_rails 0.8.6 → 0.9.1
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/.rspec +3 -3
- data/.travis.yml +5 -5
- data/CODE_OF_CONDUCT.md +74 -74
- data/LICENSE.txt +21 -21
- data/lib/rad_core_rails/query_generator.rb +21 -14
- data/lib/rad_core_rails/search_terms.rb +30 -30
- data/lib/rad_core_rails/sortable.rb +14 -14
- data/lib/rad_core_rails/version.rb +1 -1
- metadata +5 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 25afa2ab283d0e2464b20d53c7277c1fbbe517a817304c7ae478bb4e84335970
|
4
|
+
data.tar.gz: 9edaa7586be8b6ac0383324ee4be4df07b5bc4e311601d61fbf8ed3fedbd6070
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d12332fbf8ececde8084ff0db21d9587c95fad46f851993dcfa2ad2e8211fb4b21cf74850a52fd6c40d8ae9e718bb7dfc48d03295552a091ca356c2d06905d4e
|
7
|
+
data.tar.gz: 2d7a5335aa20f9abff6f976ae44084ca3f215da2ab78674ce2199c97f959f4be836268b9f50f9baa3cef7262cf00fc3ab58582986b5bb814b850d29d69a65bb7
|
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
|
data/.travis.yml
CHANGED
@@ -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
|
data/CODE_OF_CONDUCT.md
CHANGED
@@ -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/
|
data/LICENSE.txt
CHANGED
@@ -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.
|
@@ -178,12 +178,13 @@ module RadCoreRails
|
|
178
178
|
[str, args]
|
179
179
|
end
|
180
180
|
|
181
|
-
def generate_model_clause(column_name, filter, optional_exclusion_clause = nil)
|
181
|
+
def generate_model_clause(column_name, filter, optional_exclusion_clause = nil, optional_blank_clause = nil)
|
182
182
|
if optional_exclusion_clause.present? && filter[:option] == '!='
|
183
183
|
str = optional_exclusion_clause
|
184
184
|
args = [filter[:values]]
|
185
185
|
elsif filter[:option] == '!!'
|
186
|
-
|
186
|
+
optional_blank_clause ||= "(#{column_name} IS NULL)"
|
187
|
+
str = optional_blank_clause
|
187
188
|
args = []
|
188
189
|
else
|
189
190
|
# probably should fix this.
|
@@ -205,14 +206,14 @@ module RadCoreRails
|
|
205
206
|
else
|
206
207
|
# probably should fix this.
|
207
208
|
# somtimes we arent sending a filter option, so just default it to =
|
208
|
-
str = "(#{column_name} #{filter[:option] || '='} ANY(ARRAY[?]))"
|
209
|
-
args = [filter[:values]]
|
209
|
+
str = "(LOWER(TRIM(#{column_name})) #{filter[:option] || '='} ANY(ARRAY[?]))"
|
210
|
+
args = [filter[:values].map(&:strip).map(&:downcase)]
|
210
211
|
end
|
211
212
|
|
212
213
|
[str, args]
|
213
214
|
end
|
214
215
|
|
215
|
-
def sanitize_vector_string(search)
|
216
|
+
def sanitize_vector_string(search, weight = ':*')
|
216
217
|
phrases_or = search.scan(/\+"([^"]*)"/) # e.g. +"Phrase for OR"
|
217
218
|
# remove 'or' phrases from search if any
|
218
219
|
phrases_or.each { |phrase| search.gsub!('+"' + phrase.first.to_s + '"', '') } if phrases_or.any?
|
@@ -227,17 +228,17 @@ module RadCoreRails
|
|
227
228
|
|
228
229
|
sanitized_and_terms = search.split(' ')
|
229
230
|
.reject { |term| term.include?('+') || term.include?('-') }
|
230
|
-
.map { |term| term.downcase.strip +
|
231
|
+
.map { |term| term.downcase.strip + weight }
|
231
232
|
.reject { |t| t.blank? }
|
232
233
|
|
233
234
|
sanitized_or_terms = search.split(' ')
|
234
235
|
.select { |term| term.include?('+') }
|
235
|
-
.map { |term| term[1, term.length].downcase +
|
236
|
+
.map { |term| term[1, term.length].downcase + weight }
|
236
237
|
.reject { |t| t.blank? }
|
237
238
|
|
238
239
|
sanitized_excluded_terms = search.split(' ')
|
239
240
|
.select { |term| term.include?('-') }
|
240
|
-
.map { |term| term[1, term.length].downcase.strip +
|
241
|
+
.map { |term| term[1, term.length].downcase.strip + weight }
|
241
242
|
.reject { |t| t.blank? }
|
242
243
|
|
243
244
|
and_clause = sanitized_and_terms.join(' & ')
|
@@ -274,18 +275,24 @@ module RadCoreRails
|
|
274
275
|
end
|
275
276
|
end
|
276
277
|
|
277
|
-
def generate_vector_clause(column_name, filter)
|
278
|
+
def generate_vector_clause(column_name, actual_column, filter, weight = ':*')
|
279
|
+
return ["(#{actual_column} IS NULL OR #{actual_column} = '')", []] if filter[:option] == '!!'
|
278
280
|
return ['', []] if filter[:values][0].blank?
|
279
281
|
|
280
|
-
vector_string = sanitize_vector_string(filter[:values][0])
|
282
|
+
vector_string = sanitize_vector_string(filter[:values][0], weight)
|
281
283
|
|
282
|
-
query = "(#{column_name} @@ to_tsquery('simple', ?))"
|
283
|
-
[query, [vector_string]]
|
284
|
+
query = "(#{column_name} @@ to_tsquery('simple', ?) OR #{column_name} @@ to_tsquery('english', ?))"
|
285
|
+
[query, [vector_string, vector_string]]
|
284
286
|
end
|
285
287
|
|
286
288
|
def generate_zip_codes_clause(column_name, filter)
|
287
|
-
|
288
|
-
|
289
|
+
if filter[:option] != '!!'
|
290
|
+
str = "(#{column_name} = ANY(#{zip_code_class.distance_query}))"
|
291
|
+
args = zip_code_class.distance_args(filter)
|
292
|
+
elsif filter[:option] == '!!'
|
293
|
+
str = "(#{column_name} IS NULL OR #{column_name} = '')"
|
294
|
+
args = []
|
295
|
+
end
|
289
296
|
|
290
297
|
[str, args]
|
291
298
|
end
|
@@ -1,31 +1,31 @@
|
|
1
|
-
module RadCoreRails
|
2
|
-
module SearchTerms
|
3
|
-
extend ActiveSupport::Concern
|
4
|
-
|
5
|
-
class_methods do
|
6
|
-
def _terms(column, search = '')
|
7
|
-
if search.present?
|
8
|
-
if column.is_a?(Array)
|
9
|
-
terms = []
|
10
|
-
search.split(' ').each do |term|
|
11
|
-
columns = []
|
12
|
-
column.each do |col|
|
13
|
-
columns.push("(replace(lower(#{Arel.sql(col)}), ' ', '') ILIKE '%#{Arel.sql(term.downcase)}%')")
|
14
|
-
end
|
15
|
-
terms.push '(' + columns.join(' OR ') + ')'
|
16
|
-
end
|
17
|
-
'(' + terms.join(' AND ') + ')'
|
18
|
-
else
|
19
|
-
terms = []
|
20
|
-
search.split(' ').each do |term|
|
21
|
-
terms.push("(replace(lower(#{Arel.sql(column)}), ' ', '') ILIKE '%#{Arel.sql(term.downcase)}%')")
|
22
|
-
end
|
23
|
-
'(' + terms.join(' AND ') + ')'
|
24
|
-
end
|
25
|
-
else
|
26
|
-
'1 = 1'
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|
30
|
-
end
|
1
|
+
module RadCoreRails
|
2
|
+
module SearchTerms
|
3
|
+
extend ActiveSupport::Concern
|
4
|
+
|
5
|
+
class_methods do
|
6
|
+
def _terms(column, search = '')
|
7
|
+
if search.present?
|
8
|
+
if column.is_a?(Array)
|
9
|
+
terms = []
|
10
|
+
search.split(' ').each do |term|
|
11
|
+
columns = []
|
12
|
+
column.each do |col|
|
13
|
+
columns.push("(replace(lower(#{Arel.sql(col)}), ' ', '') ILIKE '%#{Arel.sql(term.downcase)}%')")
|
14
|
+
end
|
15
|
+
terms.push '(' + columns.join(' OR ') + ')'
|
16
|
+
end
|
17
|
+
'(' + terms.join(' AND ') + ')'
|
18
|
+
else
|
19
|
+
terms = []
|
20
|
+
search.split(' ').each do |term|
|
21
|
+
terms.push("(replace(lower(#{Arel.sql(column)}), ' ', '') ILIKE '%#{Arel.sql(term.downcase)}%')")
|
22
|
+
end
|
23
|
+
'(' + terms.join(' AND ') + ')'
|
24
|
+
end
|
25
|
+
else
|
26
|
+
'1 = 1'
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
31
|
end
|
@@ -1,14 +1,14 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
module RadCoreRails
|
3
|
-
module Sortable
|
4
|
-
extend ActiveSupport::Concern
|
5
|
-
|
6
|
-
included do
|
7
|
-
scope :sort_order, ->(column, direction) { order(self.sort_column(column, direction)) }
|
8
|
-
|
9
|
-
def self.sort_column(column, direction)
|
10
|
-
"#{Arel.sql(column)} #{sort_direction(direction)}"
|
11
|
-
end
|
12
|
-
end
|
13
|
-
end
|
14
|
-
end
|
1
|
+
# frozen_string_literal: true
|
2
|
+
module RadCoreRails
|
3
|
+
module Sortable
|
4
|
+
extend ActiveSupport::Concern
|
5
|
+
|
6
|
+
included do
|
7
|
+
scope :sort_order, ->(column, direction) { order(self.sort_column(column, direction)) }
|
8
|
+
|
9
|
+
def self.sort_column(column, direction)
|
10
|
+
"#{Arel.sql(column)} #{sort_direction(direction)}"
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rad_core_rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.9.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Oleksandr Poltavets, James Marrs
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-08-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -89,7 +89,7 @@ metadata:
|
|
89
89
|
homepage_uri: https://github.com/jamesmarrs/rad-core-rails
|
90
90
|
source_code_uri: https://rubygems.org/gems/rad_core_rails
|
91
91
|
changelog_uri: https://rubygems.org/gems/rad_core_rails
|
92
|
-
post_install_message:
|
92
|
+
post_install_message:
|
93
93
|
rdoc_options: []
|
94
94
|
require_paths:
|
95
95
|
- lib
|
@@ -105,7 +105,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
105
105
|
version: '0'
|
106
106
|
requirements: []
|
107
107
|
rubygems_version: 3.1.2
|
108
|
-
signing_key:
|
108
|
+
signing_key:
|
109
109
|
specification_version: 4
|
110
110
|
summary: RadCoreRails
|
111
111
|
test_files: []
|