rokaki 0.8.4 → 0.10.0
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/.github/workflows/codeql-analysis.yml +70 -0
- data/.github/workflows/spec.yml +39 -0
- data/.ruby-version +1 -1
- data/Gemfile.lock +113 -52
- data/LICENSE.txt +1 -1
- data/README.md +18 -1
- data/lib/rokaki/filter_model/basic_filter.rb +32 -2
- data/lib/rokaki/filter_model/nested_filter.rb +18 -3
- data/lib/rokaki/filter_model/nested_like_filters.rb +1 -3
- data/lib/rokaki/filter_model.rb +54 -3
- data/lib/rokaki/filterable.rb +3 -3
- data/lib/rokaki/version.rb +1 -1
- data/rokaki.gemspec +1 -0
- metadata +19 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5dac3a2881b83e34f6e0ee5717c4103212b3c4606b0ca05420338544a56cdffd
|
4
|
+
data.tar.gz: 594b1e1ff90e0a86674ed06e0de962a3cf622814cc87f02317a1da4ddcceb437
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1246c456cd8c613d8288a5d6bc69c65eedd67545b854b2185f512b071a04e1341c9bffe9f86a713ab9106842a8b015a73b0f8f55e9d0fecf8741b47e824c015b
|
7
|
+
data.tar.gz: 2429fb0148ca0705edcf02bb434541968db87a7bda6cd26a0945d1ccec660b6a9ca45ff9f5798aeeedfd4f89371f3c1575f2d0f79d1914a695b4f898d35bf4b4
|
@@ -0,0 +1,70 @@
|
|
1
|
+
# For most projects, this workflow file will not need changing; you simply need
|
2
|
+
# to commit it to your repository.
|
3
|
+
#
|
4
|
+
# You may wish to alter this file to override the set of languages analyzed,
|
5
|
+
# or to provide custom queries or build logic.
|
6
|
+
#
|
7
|
+
# ******** NOTE ********
|
8
|
+
# We have attempted to detect the languages in your repository. Please check
|
9
|
+
# the `language` matrix defined below to confirm you have the correct set of
|
10
|
+
# supported CodeQL languages.
|
11
|
+
#
|
12
|
+
name: "CodeQL"
|
13
|
+
|
14
|
+
on:
|
15
|
+
push:
|
16
|
+
branches: [ master ]
|
17
|
+
pull_request:
|
18
|
+
# The branches below must be a subset of the branches above
|
19
|
+
branches: [ master ]
|
20
|
+
schedule:
|
21
|
+
- cron: '17 0 * * 5'
|
22
|
+
|
23
|
+
jobs:
|
24
|
+
analyze:
|
25
|
+
name: Analyze
|
26
|
+
runs-on: ubuntu-latest
|
27
|
+
permissions:
|
28
|
+
actions: read
|
29
|
+
contents: read
|
30
|
+
security-events: write
|
31
|
+
|
32
|
+
strategy:
|
33
|
+
fail-fast: false
|
34
|
+
matrix:
|
35
|
+
language: [ 'ruby' ]
|
36
|
+
# CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python', 'ruby' ]
|
37
|
+
# Learn more about CodeQL language support at https://git.io/codeql-language-support
|
38
|
+
|
39
|
+
steps:
|
40
|
+
- name: Checkout repository
|
41
|
+
uses: actions/checkout@v2
|
42
|
+
|
43
|
+
# Initializes the CodeQL tools for scanning.
|
44
|
+
- name: Initialize CodeQL
|
45
|
+
uses: github/codeql-action/init@v3
|
46
|
+
with:
|
47
|
+
languages: ${{ matrix.language }}
|
48
|
+
# If you wish to specify custom queries, you can do so here or in a config file.
|
49
|
+
# By default, queries listed here will override any specified in a config file.
|
50
|
+
# Prefix the list here with "+" to use these queries and those in the config file.
|
51
|
+
# queries: ./path/to/local/query, your-org/your-repo/queries@main
|
52
|
+
|
53
|
+
# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
|
54
|
+
# If this step fails, then you should remove it and run the build manually (see below)
|
55
|
+
- name: Autobuild
|
56
|
+
uses: github/codeql-action/autobuild@v3
|
57
|
+
|
58
|
+
# ℹ️ Command-line programs to run using the OS shell.
|
59
|
+
# 📚 https://git.io/JvXDl
|
60
|
+
|
61
|
+
# ✏️ If the Autobuild fails above, remove it and uncomment the following three lines
|
62
|
+
# and modify them (or add more) to build your code if your project
|
63
|
+
# uses a compiled language
|
64
|
+
|
65
|
+
#- run: |
|
66
|
+
# make bootstrap
|
67
|
+
# make release
|
68
|
+
|
69
|
+
- name: Perform CodeQL Analysis
|
70
|
+
uses: github/codeql-action/analyze@v3
|
@@ -0,0 +1,39 @@
|
|
1
|
+
name: Run RSpec tests
|
2
|
+
on: [push]
|
3
|
+
jobs:
|
4
|
+
run-rspec-tests:
|
5
|
+
runs-on: ubuntu-latest
|
6
|
+
services:
|
7
|
+
mysql:
|
8
|
+
image: mysql:9.4
|
9
|
+
env:
|
10
|
+
MYSQL_DATABASE: rokaki
|
11
|
+
MYSQL_USER: rokaki
|
12
|
+
MYSQL_PASSWORD: rokaki
|
13
|
+
MYSQL_ROOT_PASSWORD: rokaki
|
14
|
+
ports:
|
15
|
+
- 3306:3306
|
16
|
+
options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3
|
17
|
+
|
18
|
+
postgres:
|
19
|
+
image: postgres:13
|
20
|
+
env:
|
21
|
+
POSTGRES_USER: postgres
|
22
|
+
POSTGRES_PASSWORD: "postgres"
|
23
|
+
POSTGRES_DB: rokaki
|
24
|
+
ports:
|
25
|
+
- 5432:5432
|
26
|
+
# needed because the postgres container does not provide a healthcheck
|
27
|
+
options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5
|
28
|
+
steps:
|
29
|
+
- uses: actions/checkout@v2
|
30
|
+
- name: Set up Ruby
|
31
|
+
uses: ruby/setup-ruby@v1
|
32
|
+
with:
|
33
|
+
# Not needed with a .ruby-version file
|
34
|
+
ruby-version: 3.3.0
|
35
|
+
# runs 'bundle install' and caches installed gems automatically
|
36
|
+
bundler-cache: true
|
37
|
+
- name: Run tests
|
38
|
+
run: |
|
39
|
+
./spec/ordered_run.sh
|
data/.ruby-version
CHANGED
@@ -1 +1 @@
|
|
1
|
-
|
1
|
+
3.3.0
|
data/Gemfile.lock
CHANGED
@@ -1,41 +1,66 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
rokaki (0.
|
4
|
+
rokaki (0.10.0)
|
5
5
|
activesupport
|
6
6
|
|
7
7
|
GEM
|
8
8
|
remote: https://rubygems.org/
|
9
9
|
specs:
|
10
|
-
activemodel (
|
11
|
-
activesupport (=
|
12
|
-
activerecord (
|
13
|
-
activemodel (=
|
14
|
-
activesupport (=
|
15
|
-
|
16
|
-
|
10
|
+
activemodel (8.0.3)
|
11
|
+
activesupport (= 8.0.3)
|
12
|
+
activerecord (8.0.3)
|
13
|
+
activemodel (= 8.0.3)
|
14
|
+
activesupport (= 8.0.3)
|
15
|
+
timeout (>= 0.4.0)
|
16
|
+
activesupport (8.0.3)
|
17
|
+
base64
|
18
|
+
benchmark (>= 0.3)
|
19
|
+
bigdecimal
|
20
|
+
concurrent-ruby (~> 1.0, >= 1.3.1)
|
21
|
+
connection_pool (>= 2.2.5)
|
22
|
+
drb
|
17
23
|
i18n (>= 1.6, < 2)
|
24
|
+
logger (>= 1.4.2)
|
18
25
|
minitest (>= 5.1)
|
19
|
-
|
20
|
-
|
21
|
-
|
26
|
+
securerandom (>= 0.3)
|
27
|
+
tzinfo (~> 2.0, >= 2.0.5)
|
28
|
+
uri (>= 0.13.1)
|
29
|
+
base64 (0.3.0)
|
30
|
+
benchmark (0.4.1)
|
31
|
+
bigdecimal (3.2.3)
|
32
|
+
byebug (12.0.0)
|
22
33
|
coderay (1.1.3)
|
23
|
-
concurrent-ruby (1.
|
24
|
-
|
25
|
-
database_cleaner-active_record (
|
26
|
-
activerecord
|
27
|
-
database_cleaner (~>
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
+
concurrent-ruby (1.3.5)
|
35
|
+
connection_pool (2.5.4)
|
36
|
+
database_cleaner-active_record (2.2.2)
|
37
|
+
activerecord (>= 5.a)
|
38
|
+
database_cleaner-core (~> 2.0)
|
39
|
+
database_cleaner-core (2.0.1)
|
40
|
+
diff-lcs (1.6.2)
|
41
|
+
drb (2.2.3)
|
42
|
+
factory_bot (6.5.5)
|
43
|
+
activesupport (>= 6.1.0)
|
44
|
+
ffi (1.17.2-aarch64-linux-gnu)
|
45
|
+
ffi (1.17.2-aarch64-linux-musl)
|
46
|
+
ffi (1.17.2-arm-linux-gnu)
|
47
|
+
ffi (1.17.2-arm-linux-musl)
|
48
|
+
ffi (1.17.2-arm64-darwin)
|
49
|
+
ffi (1.17.2-x86-linux-gnu)
|
50
|
+
ffi (1.17.2-x86-linux-musl)
|
51
|
+
ffi (1.17.2-x86_64-darwin)
|
52
|
+
ffi (1.17.2-x86_64-linux-gnu)
|
53
|
+
ffi (1.17.2-x86_64-linux-musl)
|
54
|
+
formatador (1.2.1)
|
55
|
+
reline
|
56
|
+
guard (2.19.1)
|
34
57
|
formatador (>= 0.2.4)
|
35
58
|
listen (>= 2.7, < 4.0)
|
59
|
+
logger (~> 1.6)
|
36
60
|
lumberjack (>= 1.0.12, < 2.0)
|
37
61
|
nenv (~> 0.1)
|
38
62
|
notiffany (~> 0.0)
|
63
|
+
ostruct (~> 0.6)
|
39
64
|
pry (>= 0.13.0)
|
40
65
|
shellany (~> 0.0)
|
41
66
|
thor (>= 0.18.1)
|
@@ -44,51 +69,86 @@ GEM
|
|
44
69
|
guard (~> 2.1)
|
45
70
|
guard-compat (~> 1.1)
|
46
71
|
rspec (>= 2.99.0, < 4.0)
|
47
|
-
i18n (1.
|
72
|
+
i18n (1.14.7)
|
48
73
|
concurrent-ruby (~> 1.0)
|
49
|
-
|
74
|
+
io-console (0.8.1)
|
75
|
+
listen (3.9.0)
|
50
76
|
rb-fsevent (~> 0.10, >= 0.10.3)
|
51
77
|
rb-inotify (~> 0.9, >= 0.9.10)
|
52
|
-
|
53
|
-
|
54
|
-
|
78
|
+
logger (1.7.0)
|
79
|
+
lumberjack (1.4.2)
|
80
|
+
method_source (1.1.0)
|
81
|
+
minitest (5.25.5)
|
82
|
+
mysql2 (0.5.7)
|
83
|
+
bigdecimal
|
55
84
|
nenv (0.3.0)
|
56
85
|
notiffany (0.1.3)
|
57
86
|
nenv (~> 0.1)
|
58
87
|
shellany (~> 0.0)
|
59
|
-
|
60
|
-
|
88
|
+
ostruct (0.6.3)
|
89
|
+
pg (1.6.2)
|
90
|
+
pg (1.6.2-aarch64-linux)
|
91
|
+
pg (1.6.2-aarch64-linux-musl)
|
92
|
+
pg (1.6.2-arm64-darwin)
|
93
|
+
pg (1.6.2-x86_64-darwin)
|
94
|
+
pg (1.6.2-x86_64-linux)
|
95
|
+
pg (1.6.2-x86_64-linux-musl)
|
96
|
+
pry (0.15.2)
|
61
97
|
coderay (~> 1.1)
|
62
98
|
method_source (~> 1.0)
|
63
|
-
pry-byebug (3.
|
64
|
-
byebug (~>
|
65
|
-
pry (
|
66
|
-
rake (13.0
|
67
|
-
rb-fsevent (0.11.
|
68
|
-
rb-inotify (0.
|
99
|
+
pry-byebug (3.11.0)
|
100
|
+
byebug (~> 12.0)
|
101
|
+
pry (>= 0.13, < 0.16)
|
102
|
+
rake (13.3.0)
|
103
|
+
rb-fsevent (0.11.2)
|
104
|
+
rb-inotify (0.11.1)
|
69
105
|
ffi (~> 1.0)
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
rspec-
|
74
|
-
|
75
|
-
rspec-
|
76
|
-
rspec-
|
106
|
+
reline (0.6.2)
|
107
|
+
io-console (~> 0.5)
|
108
|
+
rspec (3.13.1)
|
109
|
+
rspec-core (~> 3.13.0)
|
110
|
+
rspec-expectations (~> 3.13.0)
|
111
|
+
rspec-mocks (~> 3.13.0)
|
112
|
+
rspec-core (3.13.5)
|
113
|
+
rspec-support (~> 3.13.0)
|
114
|
+
rspec-expectations (3.13.5)
|
77
115
|
diff-lcs (>= 1.2.0, < 2.0)
|
78
|
-
rspec-support (~> 3.
|
79
|
-
rspec-mocks (3.
|
116
|
+
rspec-support (~> 3.13.0)
|
117
|
+
rspec-mocks (3.13.5)
|
80
118
|
diff-lcs (>= 1.2.0, < 2.0)
|
81
|
-
rspec-support (~> 3.
|
82
|
-
rspec-support (3.
|
119
|
+
rspec-support (~> 3.13.0)
|
120
|
+
rspec-support (3.13.6)
|
121
|
+
securerandom (0.4.1)
|
83
122
|
shellany (0.0.1)
|
84
|
-
sqlite3 (
|
85
|
-
|
86
|
-
|
123
|
+
sqlite3 (2.7.4-aarch64-linux-gnu)
|
124
|
+
sqlite3 (2.7.4-aarch64-linux-musl)
|
125
|
+
sqlite3 (2.7.4-arm-linux-gnu)
|
126
|
+
sqlite3 (2.7.4-arm-linux-musl)
|
127
|
+
sqlite3 (2.7.4-arm64-darwin)
|
128
|
+
sqlite3 (2.7.4-x86-linux-gnu)
|
129
|
+
sqlite3 (2.7.4-x86-linux-musl)
|
130
|
+
sqlite3 (2.7.4-x86_64-darwin)
|
131
|
+
sqlite3 (2.7.4-x86_64-linux-gnu)
|
132
|
+
sqlite3 (2.7.4-x86_64-linux-musl)
|
133
|
+
thor (1.4.0)
|
134
|
+
timeout (0.4.3)
|
135
|
+
tzinfo (2.0.6)
|
87
136
|
concurrent-ruby (~> 1.0)
|
88
|
-
|
137
|
+
uri (1.0.3)
|
89
138
|
|
90
139
|
PLATFORMS
|
91
|
-
|
140
|
+
aarch64-linux
|
141
|
+
aarch64-linux-gnu
|
142
|
+
aarch64-linux-musl
|
143
|
+
arm-linux-gnu
|
144
|
+
arm-linux-musl
|
145
|
+
arm64-darwin
|
146
|
+
x86-linux-gnu
|
147
|
+
x86-linux-musl
|
148
|
+
x86_64-darwin
|
149
|
+
x86_64-linux
|
150
|
+
x86_64-linux-gnu
|
151
|
+
x86_64-linux-musl
|
92
152
|
|
93
153
|
DEPENDENCIES
|
94
154
|
activerecord
|
@@ -97,6 +157,7 @@ DEPENDENCIES
|
|
97
157
|
factory_bot
|
98
158
|
guard
|
99
159
|
guard-rspec
|
160
|
+
mysql2
|
100
161
|
pg
|
101
162
|
pry
|
102
163
|
pry-byebug
|
@@ -106,4 +167,4 @@ DEPENDENCIES
|
|
106
167
|
sqlite3
|
107
168
|
|
108
169
|
BUNDLED WITH
|
109
|
-
2.
|
170
|
+
2.5.3
|
data/LICENSE.txt
CHANGED
data/README.md
CHANGED
@@ -419,7 +419,24 @@ filterable.results
|
|
419
419
|
|
420
420
|
## Development
|
421
421
|
|
422
|
-
|
422
|
+
### Ruby setup
|
423
|
+
After checking out the repo, run `bin/setup` to install dependencies.
|
424
|
+
|
425
|
+
### Setting up the test databases
|
426
|
+
|
427
|
+
#### Postgres
|
428
|
+
```
|
429
|
+
docker pull postgres
|
430
|
+
docker run --name rokaki-postgres -e POSTGRES_USER=rokaki -e POSTGRES_PASSWORD=rokaki -d -p 5432:5432 postgres
|
431
|
+
```
|
432
|
+
|
433
|
+
#### Mysql
|
434
|
+
```
|
435
|
+
docker pull mysql
|
436
|
+
docker run --name rokaki-mysql -e MYSQL_ROOT_PASSWORD=rokaki -e MYSQL_PASSWORD=rokaki -e MYSQL_DATABASE=rokaki -e MYSQL_USER=rokaki -d -p 3306:3306 mysql:latest mysqld
|
437
|
+
```
|
438
|
+
|
439
|
+
Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
423
440
|
|
424
441
|
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
425
442
|
|
@@ -33,13 +33,29 @@ module Rokaki
|
|
33
33
|
@filter_template = "@model = #{prefix}filter_#{name} if #{filter};"
|
34
34
|
end
|
35
35
|
|
36
|
+
def case_sensitive
|
37
|
+
if db == :postgres
|
38
|
+
'LIKE'
|
39
|
+
elsif db == :mysql
|
40
|
+
'LIKE BINARY'
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
def case_insensitive
|
45
|
+
if db == :postgres
|
46
|
+
'ILIKE'
|
47
|
+
elsif db == :mysql
|
48
|
+
'LIKE'
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
36
52
|
def _chain_filter_type(key)
|
37
53
|
filter = "#{prefix}#{key}"
|
38
54
|
query = ''
|
39
55
|
|
40
56
|
if like_semantics && mode = like_semantics[key]
|
41
57
|
query = build_like_query(
|
42
|
-
type:
|
58
|
+
type: case_sensitive,
|
43
59
|
query: query,
|
44
60
|
filter: filter,
|
45
61
|
mode: mode,
|
@@ -47,7 +63,7 @@ module Rokaki
|
|
47
63
|
)
|
48
64
|
elsif i_like_semantics && mode = i_like_semantics[key]
|
49
65
|
query = build_like_query(
|
50
|
-
type:
|
66
|
+
type: case_insensitive,
|
51
67
|
query: query,
|
52
68
|
filter: filter,
|
53
69
|
mode: mode,
|
@@ -60,6 +76,20 @@ module Rokaki
|
|
60
76
|
@filter_query = query
|
61
77
|
end
|
62
78
|
|
79
|
+
# # @model.where('`authors`.`first_name` LIKE BINARY :query', query: "%teev%").or(@model.where('`authors`.`first_name` LIKE BINARY :query', query: "%imi%"))
|
80
|
+
# if Array == filter
|
81
|
+
# first_term = filter.unshift
|
82
|
+
# query = "@model.where(\"#{key} #{type} ANY (ARRAY[?])\", "
|
83
|
+
# query += "prepare_terms(#{first_term}, :#{mode}))"
|
84
|
+
# filter.each { |term|
|
85
|
+
# query += ".or(@model.where(\"#{key} #{type} ANY (ARRAY[?])\", "
|
86
|
+
# query += "prepare_terms(#{first_term}, :#{mode})))"
|
87
|
+
# }
|
88
|
+
# else
|
89
|
+
# query = "@model.where(\"#{key.to_s.split(".").map { |item| "`#{item}`" }.join(".")} #{type.to_s.upcase} :query\", "
|
90
|
+
# query += "query: prepare_terms(#{filter}, \"#{type.to_s.upcase}\", :#{search_mode}))"
|
91
|
+
# end
|
92
|
+
|
63
93
|
def build_like_query(type:, query:, filter:, mode:, key:)
|
64
94
|
if db == :postgres
|
65
95
|
query = "@model.where(\"#{key} #{type} ANY (ARRAY[?])\", "
|
@@ -65,6 +65,22 @@ module Rokaki
|
|
65
65
|
current_like_key
|
66
66
|
end
|
67
67
|
|
68
|
+
def case_sensitive
|
69
|
+
if db == :postgres
|
70
|
+
'LIKE'
|
71
|
+
elsif db == :mysql
|
72
|
+
'LIKE BINARY'
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
def case_insensitive
|
77
|
+
if db == :postgres
|
78
|
+
'ILIKE'
|
79
|
+
elsif db == :mysql
|
80
|
+
'LIKE'
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
68
84
|
def _build_deep_chain(keys)
|
69
85
|
name = ''
|
70
86
|
count = keys.size - 1
|
@@ -80,9 +96,9 @@ module Rokaki
|
|
80
96
|
leaf = nil
|
81
97
|
|
82
98
|
if search_mode = find_like_key(keys)
|
83
|
-
type =
|
99
|
+
type = case_sensitive
|
84
100
|
elsif search_mode = find_i_like_key(keys)
|
85
|
-
type =
|
101
|
+
type = case_insensitive
|
86
102
|
end
|
87
103
|
leaf = keys.pop
|
88
104
|
|
@@ -144,7 +160,6 @@ module Rokaki
|
|
144
160
|
query = "where(\"#{key}.#{leaf} #{type} :query\", "
|
145
161
|
query += "query: \"%\#{#{filter}}%\")" if search_mode == :circumfix
|
146
162
|
query += "query: \"%\#{#{filter}}\")" if search_mode == :prefix
|
147
|
-
query += "query: \"\#{#{filter}}%\")" if search_mode == :suffix
|
148
163
|
end
|
149
164
|
|
150
165
|
query
|
@@ -227,9 +227,7 @@ module Rokaki
|
|
227
227
|
query += "prepare_terms(#{filter}, :#{search_mode}))"
|
228
228
|
else
|
229
229
|
query = "where(\"#{key_leaf} #{type.to_s.upcase} :query\", "
|
230
|
-
query += "query:
|
231
|
-
query += "query: \"%\#{#{filter}}\")" if search_mode == :prefix
|
232
|
-
query += "query: \"\#{#{filter}}%\")" if search_mode == :suffix
|
230
|
+
query += "query: prepare_regex_terms(#{filter}, :#{search_mode}))"
|
233
231
|
end
|
234
232
|
|
235
233
|
query
|
data/lib/rokaki/filter_model.rb
CHANGED
@@ -19,6 +19,34 @@ module Rokaki
|
|
19
19
|
end
|
20
20
|
end
|
21
21
|
|
22
|
+
def prepare_regex_terms(param, mode)
|
23
|
+
if Array === param
|
24
|
+
param_map = param.map { |term| ".*#{term}.*" } if mode == :circumfix
|
25
|
+
param_map = param.map { |term| ".*#{term}" } if mode == :prefix
|
26
|
+
param_map = param.map { |term| "#{term}.*" } if mode == :suffix
|
27
|
+
return param_map.join("|")
|
28
|
+
else
|
29
|
+
return [".*#{param}.*"] if mode == :circumfix
|
30
|
+
return [".*#{param}"] if mode == :prefix
|
31
|
+
return ["#{param}.*"] if mode == :suffix
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
# "SELECT `articles`.* FROM `articles` INNER JOIN `authors` ON `authors`.`id` = `articles`.`author_id` WHERE (`authors`.`first_name` LIKE BINARY '%teev%' OR `authors`.`first_name` LIKE BINARY '%arv%')"
|
36
|
+
def prepare_or_terms(param, type, mode)
|
37
|
+
if Array === param
|
38
|
+
param_map = param.map { |term| "%#{term}%" } if mode == :circumfix
|
39
|
+
param_map = param.map { |term| "%#{term}" } if mode == :prefix
|
40
|
+
param_map = param.map { |term| "#{term}%" } if mode == :suffix
|
41
|
+
|
42
|
+
return param_map.join(" OR #{type} ")
|
43
|
+
else
|
44
|
+
return ["%#{param}%"] if mode == :circumfix
|
45
|
+
return ["%#{param}"] if mode == :prefix
|
46
|
+
return ["#{param}%"] if mode == :suffix
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
22
50
|
|
23
51
|
module ClassMethods
|
24
52
|
include Filterable::ClassMethods
|
@@ -143,17 +171,40 @@ module Rokaki
|
|
143
171
|
end
|
144
172
|
end
|
145
173
|
|
146
|
-
def
|
174
|
+
def filter_db(db)
|
175
|
+
@_filter_db = db
|
176
|
+
end
|
177
|
+
|
178
|
+
def filter_model(model_class, db: nil)
|
179
|
+
@_filter_db = db if db
|
147
180
|
@model = (model_class.is_a?(Class) ? model_class : Object.const_get(model_class.capitalize))
|
148
181
|
class_eval "def set_model; @model ||= #{@model}; end;"
|
149
182
|
end
|
150
183
|
|
184
|
+
def case_sensitive
|
185
|
+
if @_filter_db == :postgres
|
186
|
+
'LIKE'
|
187
|
+
elsif @_filter_db == :mysql
|
188
|
+
# 'LIKE BINARY'
|
189
|
+
'REGEXP'
|
190
|
+
end
|
191
|
+
end
|
192
|
+
|
193
|
+
def case_insensitive
|
194
|
+
if @_filter_db == :postgres
|
195
|
+
'ILIKE'
|
196
|
+
elsif @_filter_db == :mysql
|
197
|
+
# 'LIKE'
|
198
|
+
'REGEXP'
|
199
|
+
end
|
200
|
+
end
|
201
|
+
|
151
202
|
def like(args)
|
152
203
|
raise ArgumentError, 'argument mush be a hash' unless args.is_a? Hash
|
153
204
|
@_like_semantics = (@_like_semantics || {}).merge(args)
|
154
205
|
|
155
206
|
like_keys = LikeKeys.new(args)
|
156
|
-
like_filters(like_keys, term_type:
|
207
|
+
like_filters(like_keys, term_type: case_sensitive)
|
157
208
|
end
|
158
209
|
|
159
210
|
def ilike(args)
|
@@ -161,7 +212,7 @@ module Rokaki
|
|
161
212
|
@i_like_semantics = (@i_like_semantics || {}).merge(args)
|
162
213
|
|
163
214
|
like_keys = LikeKeys.new(args)
|
164
|
-
like_filters(like_keys, term_type:
|
215
|
+
like_filters(like_keys, term_type: case_insensitive)
|
165
216
|
end
|
166
217
|
|
167
218
|
# the model method is called to instatiate @model from the
|
data/lib/rokaki/filterable.rb
CHANGED
@@ -85,11 +85,11 @@ module Rokaki
|
|
85
85
|
end
|
86
86
|
end
|
87
87
|
|
88
|
-
def deep_map(keys, value)
|
88
|
+
def deep_map(keys, value, &block)
|
89
89
|
if value.is_a? Hash
|
90
90
|
value.keys.map do |key|
|
91
91
|
_keys = keys.dup << key
|
92
|
-
deep_map(_keys, value[key], &
|
92
|
+
deep_map(_keys, value[key], &block)
|
93
93
|
end
|
94
94
|
end
|
95
95
|
|
@@ -99,7 +99,7 @@ module Rokaki
|
|
99
99
|
_keys = keys.dup << av
|
100
100
|
yield _keys
|
101
101
|
else
|
102
|
-
deep_map(keys, av, &
|
102
|
+
deep_map(keys, av, &block)
|
103
103
|
end
|
104
104
|
end
|
105
105
|
end
|
data/lib/rokaki/version.rb
CHANGED
data/rokaki.gemspec
CHANGED
@@ -44,6 +44,7 @@ Gem::Specification.new do |spec|
|
|
44
44
|
spec.add_development_dependency 'factory_bot'
|
45
45
|
|
46
46
|
spec.add_development_dependency 'pg'
|
47
|
+
spec.add_development_dependency 'mysql2'
|
47
48
|
spec.add_development_dependency 'sqlite3'
|
48
49
|
spec.add_development_dependency 'database_cleaner-active_record'
|
49
50
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rokaki
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.10.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Steve Martin
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2025-10-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -164,6 +164,20 @@ dependencies:
|
|
164
164
|
- - ">="
|
165
165
|
- !ruby/object:Gem::Version
|
166
166
|
version: '0'
|
167
|
+
- !ruby/object:Gem::Dependency
|
168
|
+
name: mysql2
|
169
|
+
requirement: !ruby/object:Gem::Requirement
|
170
|
+
requirements:
|
171
|
+
- - ">="
|
172
|
+
- !ruby/object:Gem::Version
|
173
|
+
version: '0'
|
174
|
+
type: :development
|
175
|
+
prerelease: false
|
176
|
+
version_requirements: !ruby/object:Gem::Requirement
|
177
|
+
requirements:
|
178
|
+
- - ">="
|
179
|
+
- !ruby/object:Gem::Version
|
180
|
+
version: '0'
|
167
181
|
- !ruby/object:Gem::Dependency
|
168
182
|
name: sqlite3
|
169
183
|
requirement: !ruby/object:Gem::Requirement
|
@@ -199,6 +213,8 @@ executables: []
|
|
199
213
|
extensions: []
|
200
214
|
extra_rdoc_files: []
|
201
215
|
files:
|
216
|
+
- ".github/workflows/codeql-analysis.yml"
|
217
|
+
- ".github/workflows/spec.yml"
|
202
218
|
- ".gitignore"
|
203
219
|
- ".rspec"
|
204
220
|
- ".ruby-version"
|
@@ -244,7 +260,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
244
260
|
- !ruby/object:Gem::Version
|
245
261
|
version: '0'
|
246
262
|
requirements: []
|
247
|
-
rubygems_version: 3.
|
263
|
+
rubygems_version: 3.5.3
|
248
264
|
signing_key:
|
249
265
|
specification_version: 4
|
250
266
|
summary: A web request filtering library
|