searchable-by 0.5.8 → 0.5.9
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/ruby.yml +21 -0
- data/Gemfile.lock +13 -13
- data/lib/searchable_by/column.rb +4 -2
- data/searchable-by.gemspec +2 -2
- data/spec/searchable_by_spec.rb +12 -0
- data/spec/spec_helper.rb +4 -2
- metadata +4 -4
- data/.travis.yml +0 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8b6f1b26859c89dfec031b51501c3f1dd6e8050d27bf7ae00bdb0ef9b8495422
|
4
|
+
data.tar.gz: a24dc8497c85648498fccffd56aaa4f995d7c31b48ab21e970356115a6a1ec50
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 33f4d29187d4bf9545af72632b1c17742be5ceeb3b699d36dc6e0f251151dabb06877269378d17f72dcb152f4413265866b9e076c537f5f0e1cf3f12689d3492
|
7
|
+
data.tar.gz: 6cba46e2c5ee6bf164490d5f7e2b7c715ae19dcc51d6eafbc3e93283e4d02e887e926eadc821753cf4b25522b5adb4322ac37a89d678beb76c33b7fd79fb193a
|
@@ -0,0 +1,21 @@
|
|
1
|
+
name: Ruby
|
2
|
+
|
3
|
+
on:
|
4
|
+
push:
|
5
|
+
branches: [main]
|
6
|
+
pull_request:
|
7
|
+
branches: [main]
|
8
|
+
|
9
|
+
jobs:
|
10
|
+
test:
|
11
|
+
runs-on: ubuntu-latest
|
12
|
+
strategy:
|
13
|
+
matrix:
|
14
|
+
ruby-version: ["2.6", "2.7", "3.0"]
|
15
|
+
steps:
|
16
|
+
- uses: actions/checkout@v2
|
17
|
+
- uses: ruby/setup-ruby@v1
|
18
|
+
with:
|
19
|
+
ruby-version: ${{ matrix.ruby-version }}
|
20
|
+
bundler-cache: true
|
21
|
+
- run: bundle exec rake
|
data/Gemfile.lock
CHANGED
@@ -1,19 +1,19 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
searchable-by (0.5.
|
4
|
+
searchable-by (0.5.9)
|
5
5
|
activerecord
|
6
6
|
activesupport
|
7
7
|
|
8
8
|
GEM
|
9
9
|
remote: http://rubygems.org/
|
10
10
|
specs:
|
11
|
-
activemodel (6.1.
|
12
|
-
activesupport (= 6.1.
|
13
|
-
activerecord (6.1.
|
14
|
-
activemodel (= 6.1.
|
15
|
-
activesupport (= 6.1.
|
16
|
-
activesupport (6.1.
|
11
|
+
activemodel (6.1.3)
|
12
|
+
activesupport (= 6.1.3)
|
13
|
+
activerecord (6.1.3)
|
14
|
+
activemodel (= 6.1.3)
|
15
|
+
activesupport (= 6.1.3)
|
16
|
+
activesupport (6.1.3)
|
17
17
|
concurrent-ruby (~> 1.0, >= 1.0.2)
|
18
18
|
i18n (>= 1.6, < 2)
|
19
19
|
minitest (>= 5.1)
|
@@ -22,16 +22,16 @@ GEM
|
|
22
22
|
ast (2.4.2)
|
23
23
|
concurrent-ruby (1.1.8)
|
24
24
|
diff-lcs (1.4.4)
|
25
|
-
i18n (1.8.
|
25
|
+
i18n (1.8.9)
|
26
26
|
concurrent-ruby (~> 1.0)
|
27
|
-
minitest (5.14.
|
27
|
+
minitest (5.14.4)
|
28
28
|
parallel (1.20.1)
|
29
29
|
parser (3.0.0.0)
|
30
30
|
ast (~> 2.4.1)
|
31
31
|
rack (2.2.3)
|
32
32
|
rainbow (3.0.0)
|
33
33
|
rake (13.0.3)
|
34
|
-
regexp_parser (2.
|
34
|
+
regexp_parser (2.1.1)
|
35
35
|
rexml (3.2.4)
|
36
36
|
rspec (3.10.0)
|
37
37
|
rspec-core (~> 3.10.0)
|
@@ -46,7 +46,7 @@ GEM
|
|
46
46
|
diff-lcs (>= 1.2.0, < 2.0)
|
47
47
|
rspec-support (~> 3.10.0)
|
48
48
|
rspec-support (3.10.2)
|
49
|
-
rubocop (1.
|
49
|
+
rubocop (1.11.0)
|
50
50
|
parallel (~> 1.10)
|
51
51
|
parser (>= 3.0.0.0)
|
52
52
|
rainbow (>= 2.2.2, < 4.0)
|
@@ -63,7 +63,7 @@ GEM
|
|
63
63
|
rubocop-rails
|
64
64
|
rubocop-rake
|
65
65
|
rubocop-rspec
|
66
|
-
rubocop-performance (1.
|
66
|
+
rubocop-performance (1.10.1)
|
67
67
|
rubocop (>= 0.90.0, < 2.0)
|
68
68
|
rubocop-ast (>= 0.4.0)
|
69
69
|
rubocop-rails (2.9.1)
|
@@ -95,4 +95,4 @@ DEPENDENCIES
|
|
95
95
|
sqlite3
|
96
96
|
|
97
97
|
BUNDLED WITH
|
98
|
-
2.2.
|
98
|
+
2.2.5
|
data/lib/searchable_by/column.rb
CHANGED
@@ -1,14 +1,15 @@
|
|
1
1
|
module SearchableBy
|
2
2
|
class Column
|
3
|
-
attr_reader :attr, :type, :match, :match_phrase, :min_length
|
3
|
+
attr_reader :attr, :type, :match, :match_phrase, :min_length, :wildcard
|
4
4
|
attr_accessor :node
|
5
5
|
|
6
|
-
def initialize(attr, type: :string, match: :all, match_phrase: nil, min_length: 0)
|
6
|
+
def initialize(attr, type: :string, match: :all, match_phrase: nil, min_length: 0, wildcard: nil) # rubocop:disable Metrics/ParameterLists
|
7
7
|
@attr = attr
|
8
8
|
@type = type.to_sym
|
9
9
|
@match = match
|
10
10
|
@match_phrase = match_phrase || match
|
11
11
|
@min_length = min_length
|
12
|
+
@wildcard = wildcard
|
12
13
|
end
|
13
14
|
|
14
15
|
def build_condition(value)
|
@@ -47,6 +48,7 @@ module SearchableBy
|
|
47
48
|
else
|
48
49
|
term.gsub!('%', '\%')
|
49
50
|
term.gsub!('_', '\_')
|
51
|
+
term.gsub!(wildcard, '%') if wildcard
|
50
52
|
scope.and(node.matches("%#{term}%"))
|
51
53
|
end
|
52
54
|
end
|
data/searchable-by.gemspec
CHANGED
@@ -1,12 +1,12 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
s.name = 'searchable-by'
|
3
|
-
s.version = '0.5.
|
3
|
+
s.version = '0.5.9'
|
4
4
|
s.authors = ['Dimitrij Denissenko']
|
5
5
|
s.email = ['dimitrij@blacksquaremedia.com']
|
6
6
|
s.summary = 'Generate search scopes'
|
7
7
|
s.description = 'ActiveRecord plugin'
|
8
8
|
s.homepage = 'https://github.com/bsm/sortable-by'
|
9
|
-
s.license = '
|
9
|
+
s.license = 'Apache-2.0'
|
10
10
|
|
11
11
|
s.files = `git ls-files -z`.split("\x0").reject {|f| f.start_with?('spec/') }
|
12
12
|
s.test_files = `git ls-files -z -- spec/*`.split("\x0")
|
data/spec/searchable_by_spec.rb
CHANGED
@@ -22,6 +22,12 @@ describe SearchableBy do
|
|
22
22
|
expect(sql).not_to include(%("posts"."id"))
|
23
23
|
expect(sql).to include(%("posts"."title" LIKE 'foo\\%bar%'))
|
24
24
|
expect(sql).to include(%("posts"."body" LIKE '%foo\\%bar%'))
|
25
|
+
|
26
|
+
sql = User.search_by('uni*dom').to_sql
|
27
|
+
expect(sql).to include(%("users"."country" LIKE '%uni%dom%'))
|
28
|
+
|
29
|
+
sql = User.search_by('"uni * dom"').to_sql
|
30
|
+
expect(sql).to include(%("users"."country" LIKE '%uni % dom%'))
|
25
31
|
end
|
26
32
|
|
27
33
|
it 'searches' do
|
@@ -74,4 +80,10 @@ describe SearchableBy do
|
|
74
80
|
it 'searches integers' do
|
75
81
|
expect(Post.search_by(POSTS[:ab1].id.to_s).count).to eq(1)
|
76
82
|
end
|
83
|
+
|
84
|
+
it 'supports wildcard searching' do
|
85
|
+
expect(User.search_by('uni*dom')).to match_array([USERS[:a]])
|
86
|
+
expect(User.search_by('uni*o')).to match_array([USERS[:a], USERS[:b]])
|
87
|
+
expect(User.search_by('uni*of*dom')).to be_empty
|
88
|
+
end
|
77
89
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -9,6 +9,7 @@ ActiveRecord::Base.connection.instance_eval do
|
|
9
9
|
create_table :users do |t|
|
10
10
|
t.string :name
|
11
11
|
t.string :bio
|
12
|
+
t.string :country
|
12
13
|
end
|
13
14
|
create_table :posts do |t|
|
14
15
|
t.integer :author_id, null: false
|
@@ -31,6 +32,7 @@ class User < AbstractModel
|
|
31
32
|
|
32
33
|
searchable_by do
|
33
34
|
column :bio, min_length: 3
|
35
|
+
column :country, wildcard: '*'
|
34
36
|
end
|
35
37
|
end
|
36
38
|
|
@@ -51,8 +53,8 @@ class Post < AbstractModel
|
|
51
53
|
end
|
52
54
|
|
53
55
|
USERS = {
|
54
|
-
a: User.create!(name: 'Alice', bio: 'First user'),
|
55
|
-
b: User.create!(name: 'Bob', bio: 'Second user'),
|
56
|
+
a: User.create!(name: 'Alice', bio: 'First user', country: 'United Kingdom'),
|
57
|
+
b: User.create!(name: 'Bob', bio: 'Second user', country: 'United States of America'),
|
56
58
|
}.freeze
|
57
59
|
|
58
60
|
POSTS = {
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: searchable-by
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.5.
|
4
|
+
version: 0.5.9
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dimitrij Denissenko
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-04-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
@@ -129,9 +129,9 @@ executables: []
|
|
129
129
|
extensions: []
|
130
130
|
extra_rdoc_files: []
|
131
131
|
files:
|
132
|
+
- ".github/workflows/ruby.yml"
|
132
133
|
- ".gitignore"
|
133
134
|
- ".rubocop.yml"
|
134
|
-
- ".travis.yml"
|
135
135
|
- Gemfile
|
136
136
|
- Gemfile.lock
|
137
137
|
- LICENSE
|
@@ -149,7 +149,7 @@ files:
|
|
149
149
|
- spec/spec_helper.rb
|
150
150
|
homepage: https://github.com/bsm/sortable-by
|
151
151
|
licenses:
|
152
|
-
-
|
152
|
+
- Apache-2.0
|
153
153
|
metadata: {}
|
154
154
|
post_install_message:
|
155
155
|
rdoc_options: []
|