db_text_search 0.2.2 → 1.0.0

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
- SHA1:
3
- metadata.gz: b0172bff01c9eb57aab0b3946ef2b867bf998860
4
- data.tar.gz: 4693691bcbeca4e5a0e8dedf9aac48fabc69d356
2
+ SHA256:
3
+ metadata.gz: 2df07aa92536965de8e524cf332fa67ee9fd9ad6fbb2a2989755a03414047c28
4
+ data.tar.gz: 5aed016ea41bd0c7c7413273c8a4a55f39fa431f3e524ae110f1c8d72cb8d1b0
5
5
  SHA512:
6
- metadata.gz: 84f63d51d4fcc3c92731101606036cd57253264c4bcbd376b03411d4a0a0e6d230702a481eb200c9d716e4f76e141ab2ce4e76971eecdc8f920aa83332b35050
7
- data.tar.gz: 3f33248a25268519669f645d22a900f214a480eadd924bf0b1fe4bdbc59a2907d5e38458c8210f475d932ebe84745663aa45a3393a7b8c75d2388ce7f847b883
6
+ metadata.gz: c23fcfa34bfd7a6f3a552dfbdeaa2d742c165897590b86083448743f701763908ee912a225f48fd9d681d79086056efa50f7a80b663b5e6dd9564d61240f365d
7
+ data.tar.gz: 558815223c1e3782cebf0726ab115548cac6dae63a7e37e59f88828a545a45d0984cf311151a63b736bd85f76ef974d9d2592d7c5c563735d0aa48c54e41848c
data/CHANGES.md CHANGED
@@ -1,3 +1,24 @@
1
+ ## Unreleased
2
+
3
+ ## v1.0.0
4
+
5
+ * We test on Rails 5.2, 6.0, 6.1, 7.0, so we're pretty sure these work.
6
+ * We test on Rails main, to find out about any impacts of new changes, this doesn't mean we know that 7.1 is supported yet.
7
+ * We no longer test on Rails < 5.2, so please use v0.3.2 or lower for guaranteed Rails 4.2 etc (however we haven't yet removed it from the gemspec, because it might still work)
8
+
9
+ ## v0.3.2
10
+
11
+ * Allow Ruby 3.0
12
+
13
+ ## v0.3.1
14
+
15
+ * Rails 6 support.
16
+ [ff16189f](https://github.com/thredded/db_text_search/commit/ff16189fdc7b1bf7b66e4bedc27483aaf3e75414)
17
+
18
+ ## v0.3.0
19
+
20
+ * **Feature** Case insensitive sorting via the new `CaseInsensitive#column_for_order(asc_or_desc)` method. Use it like `SomeModel.some_scope.order(CaseInsensitive.new(SomeModel, :some_field).column_for_order(:asc))`
21
+
1
22
  ## v0.2.2
2
23
 
3
24
  * Raises a more helpful error if the column is not found when calling
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # DbTextSearch [![Build Status](https://travis-ci.org/thredded/db_text_search.svg?branch=master)](https://travis-ci.org/thredded/db_text_search) [![Code Climate](https://codeclimate.com/github/thredded/db_text_search/badges/gpa.svg)](https://codeclimate.com/github/thredded/db_text_search) [![Test Coverage](https://codeclimate.com/github/thredded/db_text_search/badges/coverage.svg)](https://codeclimate.com/github/thredded/db_text_search/coverage)
1
+ # DbTextSearch [![Build Status](https://travis-ci.org/thredded/db_text_search.svg?branch=main)](https://travis-ci.org/thredded/db_text_search) [![Code Climate](https://codeclimate.com/github/thredded/db_text_search/badges/gpa.svg)](https://codeclimate.com/github/thredded/db_text_search) [![Test Coverage](https://codeclimate.com/github/thredded/db_text_search/badges/coverage.svg)](https://codeclimate.com/github/thredded/db_text_search/coverage)
2
2
 
3
3
  Different relational databases treat text search very differently.
4
4
  DbTextSearch provides a unified interface on top of ActiveRecord for SQLite, MySQL, and PostgreSQL to do:
@@ -11,7 +11,7 @@ DbTextSearch provides a unified interface on top of ActiveRecord for SQLite, MyS
11
11
  Add this line to your application's Gemfile:
12
12
 
13
13
  ```ruby
14
- gem 'db_text_search', '~> 0.2.2'
14
+ gem 'db_text_search', '~> 1.0'
15
15
  ```
16
16
 
17
17
  ## Usage
@@ -0,0 +1,17 @@
1
+ The checklist for releasing a new version of db_text_search.
2
+
3
+ Pre-requisites for the releaser:
4
+
5
+ * Push access to RubyGems.
6
+
7
+ Release checklist:
8
+
9
+ - [ ] Update gem version in `version.rb` and `README.md`.
10
+ - [ ] Update `CHANGELOG.md`.
11
+ - [ ] Wait for the Travis build to come back green.
12
+ - [ ] Tag the release and push it to rubygems:
13
+
14
+ ```bash
15
+ rake release
16
+ ```
17
+ - [ ] Copy the release notes from the changelog to [GitHub Releases](https://github.com/thredded/thredded/releases).
@@ -20,17 +20,15 @@ Gem::Specification.new do |s|
20
20
  s.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(spec|bin|script)/|^\.|Rakefile|Gemfile}) }
21
21
 
22
22
  s.require_paths = ['lib']
23
- s.required_ruby_version = '~> 2.1'
23
+ s.required_ruby_version = '>= 2.1', '< 4.0'
24
24
 
25
- s.add_dependency 'activerecord', '>= 4.1.15', '< 6.0'
25
+ s.add_dependency 'activerecord', '>= 4.1.15'
26
26
 
27
27
  s.add_development_dependency 'mysql2', '>= 0.3.20'
28
28
  s.add_development_dependency 'pg', '>= 0.18.4'
29
29
  s.add_development_dependency 'sqlite3', '>= 1.3.11'
30
30
 
31
- s.add_development_dependency 'bundler', '~> 1.11'
32
- s.add_development_dependency 'rake', '~> 11.0'
31
+ s.add_development_dependency 'rake', '~> 13.0'
33
32
  s.add_development_dependency 'rspec', '~> 3.4'
34
33
  s.add_development_dependency 'simplecov'
35
- s.add_development_dependency 'rubocop', '= 0.49.1'
36
34
  end
@@ -30,6 +30,13 @@ module DbTextSearch
30
30
  fail 'abstract'
31
31
  end
32
32
 
33
+ # @param asc_or_desc [Symbol]
34
+ # @return [Arel::Collectors::SQLString]
35
+ # @abstract
36
+ def column_for_order(asc_or_desc)
37
+ fail 'abstract'
38
+ end
39
+
33
40
  # Add an index for case-insensitive string search.
34
41
  #
35
42
  # @param connection [ActiveRecord::ConnectionAdapters::AbstractAdapter]
@@ -22,6 +22,11 @@ module DbTextSearch
22
22
  escaped_query
23
23
  end
24
24
 
25
+ # (see AbstractAdapter#column_for_order)
26
+ def column_for_order(asc_or_desc)
27
+ Arel.sql("#{quoted_scope_column} COLLATE NOCASE #{asc_or_desc}")
28
+ end
29
+
25
30
  # (see AbstractAdapter.add_index)
26
31
  def self.add_index(connection, table_name, column_name, options = {})
27
32
  # TODO: Switch to the native Rails solution once it's landed, as the current one requires SQL dump format.
@@ -16,9 +16,14 @@ module DbTextSearch
16
16
  @scope.where "#{quoted_scope_column} LIKE ?", "#{sanitize_sql_like(query)}%"
17
17
  end
18
18
 
19
+ # (see AbstractAdapter#column_for_order)
20
+ def column_for_order(asc_or_desc)
21
+ Arel.sql("#{quoted_scope_column} #{asc_or_desc}")
22
+ end
23
+
19
24
  # (see AbstractAdapter.add_index)
20
25
  def self.add_index(connection, table_name, column_name, options = {})
21
- connection.add_index table_name, column_name, options
26
+ connection.add_index table_name, column_name, **options
22
27
  end
23
28
  end
24
29
  end
@@ -17,6 +17,11 @@ module DbTextSearch
17
17
  @scope.where "LOWER(#{quoted_scope_column}) LIKE LOWER(?)", "#{sanitize_sql_like(query)}%"
18
18
  end
19
19
 
20
+ # (see AbstractAdapter#column_for_order)
21
+ def column_for_order(asc_or_desc)
22
+ Arel.sql("LOWER(#{quoted_scope_column}) #{asc_or_desc}")
23
+ end
24
+
20
25
  # (see AbstractAdapter.add_index)
21
26
  def self.add_index(connection, table_name, column_name, options = {})
22
27
  unsupported = -> { DbTextSearch.unsupported_adapter! connection }
@@ -29,13 +29,20 @@ module DbTextSearch
29
29
  @adapter.prefix(query)
30
30
  end
31
31
 
32
+ # @param asc_or_desc [Symbol]
33
+ # @return [Arel::Collectors::SQLString] a string to be used within an `.order()`
34
+ def column_for_order(asc_or_desc)
35
+ fail 'Pass either :asc or :desc' unless %i[asc desc].include?(asc_or_desc)
36
+ @adapter.column_for_order(asc_or_desc)
37
+ end
38
+
32
39
  # Adds a case-insensitive column to the given table.
33
40
  # @param connection [ActiveRecord::ConnectionAdapters::AbstractAdapter]
34
41
  # @param table_name [String, Symbol]
35
42
  # @param column_name [String, Symbol]
36
43
  # @param options [Hash] passed to ActiveRecord::ConnectionAdapters::SchemaStatements#add_index
37
44
  def self.add_ci_text_column(connection, table_name, column_name, options = {})
38
- connection.add_column table_name, column_name, *DbTextSearch.match_adapter(
45
+ type, options = DbTextSearch.match_adapter(
39
46
  connection,
40
47
  mysql: -> { [:text, options] },
41
48
  postgres: -> {
@@ -50,6 +57,7 @@ module DbTextSearch
50
57
  end
51
58
  }
52
59
  )
60
+ connection.add_column table_name, column_name, type, **options
53
61
  end
54
62
 
55
63
  # Add an index for case-insensitive string search.
@@ -2,5 +2,5 @@
2
2
 
3
3
  module DbTextSearch
4
4
  # Gem version
5
- VERSION = '0.2.2'
5
+ VERSION = '1.0.0'
6
6
  end
data/rubocop.gemfile ADDED
@@ -0,0 +1 @@
1
+ gem 'rubocop', '= 0.49.1'
data/shared.gemfile CHANGED
@@ -1,13 +1,4 @@
1
- if ENV['TRAVIS']
2
- group :test do
3
- gem 'codeclimate-test-reporter', require: false
4
- gem 'codeclimate_batch', require: false,
5
- # TODO: use the released version once a new release that supports
6
- # codeclimate-test-reporter v1.0+ is out.
7
- git: 'https://github.com/sethherr/codeclimate_batch',
8
- branch: 'new_simplecov'
9
- end
10
- else
1
+ unless ENV['TRAVIS']
11
2
  group :test, :development do
12
3
  gem 'byebug', platform: :mri, require: false
13
4
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: db_text_search
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gleb Mazovetskiy
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-06-10 00:00:00.000000000 Z
11
+ date: 2022-02-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -17,9 +17,6 @@ dependencies:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
19
  version: 4.1.15
20
- - - "<"
21
- - !ruby/object:Gem::Version
22
- version: '6.0'
23
20
  type: :runtime
24
21
  prerelease: false
25
22
  version_requirements: !ruby/object:Gem::Requirement
@@ -27,9 +24,6 @@ dependencies:
27
24
  - - ">="
28
25
  - !ruby/object:Gem::Version
29
26
  version: 4.1.15
30
- - - "<"
31
- - !ruby/object:Gem::Version
32
- version: '6.0'
33
27
  - !ruby/object:Gem::Dependency
34
28
  name: mysql2
35
29
  requirement: !ruby/object:Gem::Requirement
@@ -72,34 +66,20 @@ dependencies:
72
66
  - - ">="
73
67
  - !ruby/object:Gem::Version
74
68
  version: 1.3.11
75
- - !ruby/object:Gem::Dependency
76
- name: bundler
77
- requirement: !ruby/object:Gem::Requirement
78
- requirements:
79
- - - "~>"
80
- - !ruby/object:Gem::Version
81
- version: '1.11'
82
- type: :development
83
- prerelease: false
84
- version_requirements: !ruby/object:Gem::Requirement
85
- requirements:
86
- - - "~>"
87
- - !ruby/object:Gem::Version
88
- version: '1.11'
89
69
  - !ruby/object:Gem::Dependency
90
70
  name: rake
91
71
  requirement: !ruby/object:Gem::Requirement
92
72
  requirements:
93
73
  - - "~>"
94
74
  - !ruby/object:Gem::Version
95
- version: '11.0'
75
+ version: '13.0'
96
76
  type: :development
97
77
  prerelease: false
98
78
  version_requirements: !ruby/object:Gem::Requirement
99
79
  requirements:
100
80
  - - "~>"
101
81
  - !ruby/object:Gem::Version
102
- version: '11.0'
82
+ version: '13.0'
103
83
  - !ruby/object:Gem::Dependency
104
84
  name: rspec
105
85
  requirement: !ruby/object:Gem::Requirement
@@ -128,20 +108,6 @@ dependencies:
128
108
  - - ">="
129
109
  - !ruby/object:Gem::Version
130
110
  version: '0'
131
- - !ruby/object:Gem::Dependency
132
- name: rubocop
133
- requirement: !ruby/object:Gem::Requirement
134
- requirements:
135
- - - '='
136
- - !ruby/object:Gem::Version
137
- version: 0.49.1
138
- type: :development
139
- prerelease: false
140
- version_requirements: !ruby/object:Gem::Requirement
141
- requirements:
142
- - - '='
143
- - !ruby/object:Gem::Version
144
- version: 0.49.1
145
111
  description: Different relational databases treat text search very differently. DbTextSearch
146
112
  provides a unified interface on top of ActiveRecord for SQLite, MySQL, and PostgreSQL
147
113
  to do case-insensitive string-in-set querying and CI index creation, and basic full-text
@@ -156,6 +122,7 @@ files:
156
122
  - CODE_OF_CONDUCT.md
157
123
  - LICENSE.txt
158
124
  - README.md
125
+ - RELEASE-CHECKLIST.md
159
126
  - db_text_search.gemspec
160
127
  - lib/db_text_search.rb
161
128
  - lib/db_text_search/case_insensitive.rb
@@ -170,29 +137,32 @@ files:
170
137
  - lib/db_text_search/full_text/sqlite_adapter.rb
171
138
  - lib/db_text_search/query_building.rb
172
139
  - lib/db_text_search/version.rb
140
+ - rubocop.gemfile
173
141
  - shared.gemfile
174
142
  homepage: https://github.com/thredded/db_text_search
175
143
  licenses:
176
144
  - MIT
177
145
  metadata: {}
178
- post_install_message:
146
+ post_install_message:
179
147
  rdoc_options: []
180
148
  require_paths:
181
149
  - lib
182
150
  required_ruby_version: !ruby/object:Gem::Requirement
183
151
  requirements:
184
- - - "~>"
152
+ - - ">="
185
153
  - !ruby/object:Gem::Version
186
154
  version: '2.1'
155
+ - - "<"
156
+ - !ruby/object:Gem::Version
157
+ version: '4.0'
187
158
  required_rubygems_version: !ruby/object:Gem::Requirement
188
159
  requirements:
189
160
  - - ">="
190
161
  - !ruby/object:Gem::Version
191
162
  version: '0'
192
163
  requirements: []
193
- rubyforge_project:
194
- rubygems_version: 2.6.12
195
- signing_key:
164
+ rubygems_version: 3.1.6
165
+ signing_key:
196
166
  specification_version: 4
197
167
  summary: A unified interface on top of ActiveRecord for SQLite, MySQL, and PostgreSQLfor
198
168
  case-insensitive string search and basic full-text search.