searchable-by 0.5.7 → 0.5.8

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2137729d80e65107cadf27ede26a60887b6888c41f6940caea9828e3416f137f
4
- data.tar.gz: 6edd61ef3f32e0fa6e882b07f5d24004a5c7a4cd5ec2f9c99ba2e6e12332f5e2
3
+ metadata.gz: 9577dc443c9400afd9bb866e8a53a351cf1e56420ce28b140c184e6647689411
4
+ data.tar.gz: 6a84939c7bb80af91d31b6d6bb3fd65acd672a4b41fbc25dbe08664e74d1f58d
5
5
  SHA512:
6
- metadata.gz: 704a8beb8c791dc20e6d156f73a3c3b21f6aed0df0d94d0cc7dda78440d9051f4a9f9a3d076fa3afa5af54a4312e9251335d2ab2911c228506c23d877ef67789
7
- data.tar.gz: '0906f2424988065b3d22a177ab260d42029ad3e531a8b5e051fc7170d87e87784fa18225eba4f6631416af7a0c9a3df5c1b3e464babdb8d56ace5f226b18ee39'
6
+ metadata.gz: 86367f8084de15d5d8e11568c1dadd5beddb090bf4dc4c334133197e15906e0bced5396a5c95f9434e6902d2ae0752698590f1b2fc1eacba26cb49a66a3e5697
7
+ data.tar.gz: ac9f4157b9a1705b50c95c9e1e3ee4f9c19b5ea7be9fec12a5a42df53eb0a2761a0c90c902dce641f15628ac48f2b3be4e1b504cfb36bebd6db00620dda4d787
data/.rubocop.yml CHANGED
@@ -1,13 +1,12 @@
1
- require:
2
- - rubocop-performance
3
- - rubocop-rake
4
- - rubocop-rspec
5
-
6
- inherit_from:
7
- - https://gitlab.com/bsm/misc/raw/master/rubocop/default.yml
1
+ inherit_gem:
2
+ rubocop-bsm:
3
+ - default.yml
4
+ inherit_mode:
5
+ merge:
6
+ - Exclude
8
7
 
9
8
  AllCops:
10
- TargetRubyVersion: "2.5"
9
+ TargetRubyVersion: "2.6"
11
10
 
12
11
  Naming/FileName:
13
12
  Exclude:
data/.travis.yml CHANGED
@@ -1,7 +1,8 @@
1
1
  language: ruby
2
2
  rvm:
3
+ - 3.0
4
+ - 2.7
3
5
  - 2.6
4
- - 2.5
5
6
  cache: bundler
6
7
  before_install:
7
8
  - gem install bundler
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- searchable-by (0.5.7)
4
+ searchable-by (0.5.8)
5
5
  activerecord
6
6
  activesupport
7
7
 
@@ -19,15 +19,16 @@ GEM
19
19
  minitest (>= 5.1)
20
20
  tzinfo (~> 2.0)
21
21
  zeitwerk (~> 2.3)
22
- ast (2.4.1)
23
- concurrent-ruby (1.1.7)
22
+ ast (2.4.2)
23
+ concurrent-ruby (1.1.8)
24
24
  diff-lcs (1.4.4)
25
- i18n (1.8.7)
25
+ i18n (1.8.8)
26
26
  concurrent-ruby (~> 1.0)
27
27
  minitest (5.14.3)
28
28
  parallel (1.20.1)
29
29
  parser (3.0.0.0)
30
30
  ast (~> 2.4.1)
31
+ rack (2.2.3)
31
32
  rainbow (3.0.0)
32
33
  rake (13.0.3)
33
34
  regexp_parser (2.0.3)
@@ -41,11 +42,11 @@ GEM
41
42
  rspec-expectations (3.10.1)
42
43
  diff-lcs (>= 1.2.0, < 2.0)
43
44
  rspec-support (~> 3.10.0)
44
- rspec-mocks (3.10.1)
45
+ rspec-mocks (3.10.2)
45
46
  diff-lcs (>= 1.2.0, < 2.0)
46
47
  rspec-support (~> 3.10.0)
47
- rspec-support (3.10.1)
48
- rubocop (1.8.1)
48
+ rspec-support (3.10.2)
49
+ rubocop (1.9.1)
49
50
  parallel (~> 1.10)
50
51
  parser (>= 3.0.0.0)
51
52
  rainbow (>= 2.2.2, < 4.0)
@@ -54,14 +55,24 @@ GEM
54
55
  rubocop-ast (>= 1.2.0, < 2.0)
55
56
  ruby-progressbar (~> 1.7)
56
57
  unicode-display_width (>= 1.4.0, < 3.0)
57
- rubocop-ast (1.4.0)
58
+ rubocop-ast (1.4.1)
58
59
  parser (>= 2.7.1.5)
60
+ rubocop-bsm (0.5.4)
61
+ rubocop (~> 1.0)
62
+ rubocop-performance
63
+ rubocop-rails
64
+ rubocop-rake
65
+ rubocop-rspec
59
66
  rubocop-performance (1.9.2)
60
67
  rubocop (>= 0.90.0, < 2.0)
61
68
  rubocop-ast (>= 0.4.0)
69
+ rubocop-rails (2.9.1)
70
+ activesupport (>= 4.2.0)
71
+ rack (>= 1.1)
72
+ rubocop (>= 0.90.0, < 2.0)
62
73
  rubocop-rake (0.5.1)
63
74
  rubocop
64
- rubocop-rspec (2.1.0)
75
+ rubocop-rspec (2.2.0)
65
76
  rubocop (~> 1.0)
66
77
  rubocop-ast (>= 1.1.0)
67
78
  ruby-progressbar (1.11.0)
@@ -79,11 +90,9 @@ DEPENDENCIES
79
90
  rake
80
91
  rspec
81
92
  rubocop
82
- rubocop-performance
83
- rubocop-rake
84
- rubocop-rspec
93
+ rubocop-bsm
85
94
  searchable-by!
86
95
  sqlite3
87
96
 
88
97
  BUNDLED WITH
89
- 2.1.4
98
+ 2.2.3
data/README.md CHANGED
@@ -15,9 +15,10 @@ class Post < ActiveRecord::Base
15
15
  # Limit the number of terms per query to 3.
16
16
  searchable_by max_terms: 3 do
17
17
  # Allow to search strings with custom match type.
18
- # Use btree index-friendly prefix match, e.g. `ILIKE 'term%'` instead of default `ILIKE '%term%'`.
19
- # For phrases use exact match type, e.g. searching for `"My Post"` will query `WHERE LOWER(title) = 'my post'`.
20
- column :title, match: :prefix, match_phrase: :exact
18
+ column :title,
19
+ match: :prefix, # Use btree index-friendly prefix match, e.g. `ILIKE 'term%'` instead of default `ILIKE '%term%'`.
20
+ match_phrase: :exact, # For phrases use exact match type, e.g. searching for `"My Post"` will query `WHERE LOWER(title) = 'my post'`.
21
+ min_length: 3 # Return no-match if search term is too short (useful for trigram indexes).
21
22
 
22
23
  # ... and integers.
23
24
  column :id, type: :integer
@@ -1,16 +1,19 @@
1
1
  module SearchableBy
2
2
  class Column
3
- attr_reader :attr, :type, :match, :match_phrase
3
+ attr_reader :attr, :type, :match, :match_phrase, :min_length
4
4
  attr_accessor :node
5
5
 
6
- def initialize(attr, type: :string, match: :all, match_phrase: nil)
6
+ def initialize(attr, type: :string, match: :all, match_phrase: nil, min_length: 0)
7
7
  @attr = attr
8
8
  @type = type.to_sym
9
9
  @match = match
10
10
  @match_phrase = match_phrase || match
11
+ @min_length = min_length
11
12
  end
12
13
 
13
14
  def build_condition(value)
15
+ return Arel::Nodes::False.new if value.term.length < min_length # no-match
16
+
14
17
  scope = node.not_eq(nil)
15
18
 
16
19
  case type
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'searchable-by'
3
- s.version = '0.5.7'
3
+ s.version = '0.5.8'
4
4
  s.authors = ['Dimitrij Denissenko']
5
5
  s.email = ['dimitrij@blacksquaremedia.com']
6
6
  s.summary = 'Generate search scopes'
@@ -11,7 +11,7 @@ Gem::Specification.new do |s|
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")
13
13
  s.require_paths = ['lib']
14
- s.required_ruby_version = '>= 2.5'
14
+ s.required_ruby_version = '>= 2.6'
15
15
 
16
16
  s.add_dependency 'activerecord'
17
17
  s.add_dependency 'activesupport'
@@ -20,8 +20,6 @@ Gem::Specification.new do |s|
20
20
  s.add_development_dependency 'rake'
21
21
  s.add_development_dependency 'rspec'
22
22
  s.add_development_dependency 'rubocop'
23
- s.add_development_dependency 'rubocop-performance'
24
- s.add_development_dependency 'rubocop-rake'
25
- s.add_development_dependency 'rubocop-rspec'
23
+ s.add_development_dependency 'rubocop-bsm'
26
24
  s.add_development_dependency 'sqlite3'
27
25
  end
@@ -61,6 +61,11 @@ describe SearchableBy do
61
61
  expect(Post.search_by('recip').pluck(:title)).to match_array(%w[ax1 ax2 bx1 bx2 ab1])
62
62
  end
63
63
 
64
+ it 'supports min term length' do
65
+ expect(User.search_by('+ir')).to be_empty
66
+ expect(User.search_by('irs')).to match_array([USERS[:a]])
67
+ end
68
+
64
69
  it 'searches within scopes' do
65
70
  expect(Post.where(title: 'ax1').search_by('ALICE').pluck(:title)).to match_array(%w[ax1])
66
71
  expect(Post.where(title: 'ax1').search_by('bOb').pluck(:title)).to be_empty
data/spec/spec_helper.rb CHANGED
@@ -8,6 +8,7 @@ ActiveRecord::Base.establish_connection :test
8
8
  ActiveRecord::Base.connection.instance_eval do
9
9
  create_table :users do |t|
10
10
  t.string :name
11
+ t.string :bio
11
12
  end
12
13
  create_table :posts do |t|
13
14
  t.integer :author_id, null: false
@@ -27,6 +28,10 @@ end
27
28
 
28
29
  class User < AbstractModel
29
30
  has_many :posts, foreign_key: :author_id
31
+
32
+ searchable_by do
33
+ column :bio, min_length: 3
34
+ end
30
35
  end
31
36
 
32
37
  class Post < AbstractModel
@@ -46,8 +51,8 @@ class Post < AbstractModel
46
51
  end
47
52
 
48
53
  USERS = {
49
- a: User.create!(name: 'Alice'),
50
- b: User.create!(name: 'Bob'),
54
+ a: User.create!(name: 'Alice', bio: 'First user'),
55
+ b: User.create!(name: 'Bob', bio: 'Second user'),
51
56
  }.freeze
52
57
 
53
58
  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.7
4
+ version: 0.5.8
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-01-13 00:00:00.000000000 Z
11
+ date: 2021-02-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -95,35 +95,7 @@ dependencies:
95
95
  - !ruby/object:Gem::Version
96
96
  version: '0'
97
97
  - !ruby/object:Gem::Dependency
98
- name: rubocop-performance
99
- requirement: !ruby/object:Gem::Requirement
100
- requirements:
101
- - - ">="
102
- - !ruby/object:Gem::Version
103
- version: '0'
104
- type: :development
105
- prerelease: false
106
- version_requirements: !ruby/object:Gem::Requirement
107
- requirements:
108
- - - ">="
109
- - !ruby/object:Gem::Version
110
- version: '0'
111
- - !ruby/object:Gem::Dependency
112
- name: rubocop-rake
113
- requirement: !ruby/object:Gem::Requirement
114
- requirements:
115
- - - ">="
116
- - !ruby/object:Gem::Version
117
- version: '0'
118
- type: :development
119
- prerelease: false
120
- version_requirements: !ruby/object:Gem::Requirement
121
- requirements:
122
- - - ">="
123
- - !ruby/object:Gem::Version
124
- version: '0'
125
- - !ruby/object:Gem::Dependency
126
- name: rubocop-rspec
98
+ name: rubocop-bsm
127
99
  requirement: !ruby/object:Gem::Requirement
128
100
  requirements:
129
101
  - - ">="
@@ -187,7 +159,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
187
159
  requirements:
188
160
  - - ">="
189
161
  - !ruby/object:Gem::Version
190
- version: '2.5'
162
+ version: '2.6'
191
163
  required_rubygems_version: !ruby/object:Gem::Requirement
192
164
  requirements:
193
165
  - - ">="