db_text_search 0.2.0 → 0.3.2

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: 0b93fa5e6feaef447c7bd1e8580b42aafa2cca3d
4
- data.tar.gz: d1ddab5bfe8ef8cb544c711ab1b4792882578eab
2
+ SHA256:
3
+ metadata.gz: f1cd1c9c3fac9de18b145e38bbb51b61bb686aa7c4a750bb3857170ee29afdd0
4
+ data.tar.gz: 2b87d5dc1d79444fffe06eb5686de7f8bf52d2e1a1cfb650ddcc61ff1328e6c8
5
5
  SHA512:
6
- metadata.gz: ffe48a13416b0dd7d820584d411c5a4e22806738e1bc3c36fd2be0121f890b621269f62a058b3791e0322e5f51edc05c255ab0ee87958c8b4e0e1846dba41ca9
7
- data.tar.gz: b07cce34cda731a695d59da849cb0e62a0f2c2247584c32a21cf23c75afeba4382cad4d3fe2cff945e4ccd05bedcd114af44ed5248c1775c2fe5e4c3e148a016
6
+ metadata.gz: cb396b8558c1f6bce6ed3eb9f2c1c70179a729d0f22578fbadbf85503eeeef098596fb7c9dbb26e3a81bc099dcd708ba9746ff69245968de7cda9aea03aba6e1
7
+ data.tar.gz: bfaff15b9d3e0bb7416d190723e54e9900239421af12faa329f9d8bf2dd9161d9e22b6e17b402b079bd103d3218a689f0b45fa123fba0b526a764691192d2a14
data/CHANGES.md CHANGED
@@ -1,3 +1,26 @@
1
+ ## v0.3.2
2
+
3
+ * Allow Ruby 3.0
4
+
5
+ ## v0.3.1
6
+
7
+ * Rails 6 support.
8
+ [ff16189f](https://github.com/thredded/db_text_search/commit/ff16189fdc7b1bf7b66e4bedc27483aaf3e75414)
9
+
10
+ ## v0.3.0
11
+
12
+ * **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))`
13
+
14
+ ## v0.2.2
15
+
16
+ * Raises a more helpful error if the column is not found when calling
17
+ `DbTextSearch::CaseInsensitive`.
18
+
19
+ ## v0.2.1
20
+
21
+ * Support for PostGIS adapters.
22
+ [#2](https://github.com/thredded/db_text_search/issues/2)
23
+
1
24
  ## v0.2.0
2
25
 
3
26
  * **Feature** Prefix matching via the new `CaseInsensitive#prefix` method.
data/README.md CHANGED
@@ -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.0'
14
+ gem 'db_text_search', '~> 0.3.2'
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,15 +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', '< 7.0'
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'
33
+ s.add_development_dependency 'simplecov'
34
34
  end
@@ -24,7 +24,7 @@ module DbTextSearch
24
24
  case connection.adapter_name
25
25
  when /mysql/i
26
26
  mysql.call
27
- when /postgres/i
27
+ when /postg/i # match all postgres and postgis adapters
28
28
  postgres.call
29
29
  when /sqlite/i
30
30
  sqlite.call
@@ -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: -> {
@@ -48,7 +55,9 @@ module DbTextSearch
48
55
  else
49
56
  ['TEXT COLLATE NOCASE', options]
50
57
  end
51
- })
58
+ }
59
+ )
60
+ connection.add_column table_name, column_name, type, **options
52
61
  end
53
62
 
54
63
  # Add an index for case-insensitive string search.
@@ -78,7 +87,8 @@ module DbTextSearch
78
87
  postgres: lower_or_insensitive,
79
88
  # Always use COLLATE NOCASE for SQLite, as we can't check if the column is case-sensitive.
80
89
  # It has no performance impact apart from slightly longer query strings for case-insensitive columns.
81
- sqlite: -> { CollateNocaseAdapter })
90
+ sqlite: -> { CollateNocaseAdapter }
91
+ )
82
92
  end
83
93
 
84
94
  # @param connection [ActiveRecord::ConnectionAdapters::AbstractAdapter]
@@ -87,13 +97,15 @@ module DbTextSearch
87
97
  # @return [Boolean]
88
98
  # @note sqlite not supported.
89
99
  # @api private
90
- def self.column_case_sensitive?(connection, table_name, column_name)
100
+ def self.column_case_sensitive?(connection, table_name, column_name) # rubocop:disable Metrics/AbcSize
91
101
  column = connection.schema_cache.columns(table_name).detect { |c| c.name == column_name.to_s }
102
+ fail "Column #{column_name.to_s.inspect} not found on table #{table_name.inspect}" if column.nil?
92
103
  DbTextSearch.match_adapter(
93
104
  connection,
94
105
  mysql: -> { column.case_sensitive? },
95
106
  postgres: -> { column.sql_type !~ /citext/i },
96
- sqlite: -> { DbTextSearch.unsupported_adapter! connection })
107
+ sqlite: -> { DbTextSearch.unsupported_adapter! connection }
108
+ )
97
109
  end
98
110
  end
99
111
  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 }
@@ -31,7 +36,8 @@ module DbTextSearch
31
36
  connection.exec_query(quoted_create_index(connection, table_name, **options))
32
37
  },
33
38
  mysql: unsupported,
34
- sqlite: unsupported)
39
+ sqlite: unsupported
40
+ )
35
41
  end
36
42
  end
37
43
  end
@@ -49,7 +49,8 @@ module DbTextSearch
49
49
  connection,
50
50
  mysql: -> { MysqlAdapter },
51
51
  postgres: -> { PostgresAdapter },
52
- sqlite: -> { SqliteAdapter })
52
+ sqlite: -> { SqliteAdapter }
53
+ )
53
54
  end
54
55
  end
55
56
  end
@@ -20,8 +20,7 @@ module DbTextSearch
20
20
  end
21
21
 
22
22
  # A no-op, as we just use LIKE for sqlite.
23
- def self.add_index(_connection, _table_name, _column_name, name:, pg_ts_config:)
24
- end
23
+ def self.add_index(_connection, _table_name, _column_name, name:, pg_ts_config:); end
25
24
  end
26
25
  end
27
26
  end
@@ -2,5 +2,5 @@
2
2
 
3
3
  module DbTextSearch
4
4
  # Gem version
5
- VERSION = '0.2.0'
5
+ VERSION = '0.3.2'
6
6
  end
data/rubocop.gemfile ADDED
@@ -0,0 +1 @@
1
+ gem 'rubocop', '= 0.49.1'
data/shared.gemfile CHANGED
@@ -1,9 +1,4 @@
1
- if ENV['TRAVIS']
2
- group :test do
3
- gem 'codeclimate-test-reporter', require: false
4
- gem 'codeclimate_batch', require: false
5
- end
6
- else
1
+ unless ENV['TRAVIS']
7
2
  group :test, :development do
8
3
  gem 'byebug', platform: :mri, require: false
9
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.0
4
+ version: 0.3.2
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: 2016-04-06 00:00:00.000000000 Z
11
+ date: 2021-04-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -19,7 +19,7 @@ dependencies:
19
19
  version: 4.1.15
20
20
  - - "<"
21
21
  - !ruby/object:Gem::Version
22
- version: '6.0'
22
+ version: '7.0'
23
23
  type: :runtime
24
24
  prerelease: false
25
25
  version_requirements: !ruby/object:Gem::Requirement
@@ -29,7 +29,7 @@ dependencies:
29
29
  version: 4.1.15
30
30
  - - "<"
31
31
  - !ruby/object:Gem::Version
32
- version: '6.0'
32
+ version: '7.0'
33
33
  - !ruby/object:Gem::Dependency
34
34
  name: mysql2
35
35
  requirement: !ruby/object:Gem::Requirement
@@ -73,47 +73,47 @@ dependencies:
73
73
  - !ruby/object:Gem::Version
74
74
  version: 1.3.11
75
75
  - !ruby/object:Gem::Dependency
76
- name: bundler
76
+ name: rake
77
77
  requirement: !ruby/object:Gem::Requirement
78
78
  requirements:
79
79
  - - "~>"
80
80
  - !ruby/object:Gem::Version
81
- version: '1.11'
81
+ version: '13.0'
82
82
  type: :development
83
83
  prerelease: false
84
84
  version_requirements: !ruby/object:Gem::Requirement
85
85
  requirements:
86
86
  - - "~>"
87
87
  - !ruby/object:Gem::Version
88
- version: '1.11'
88
+ version: '13.0'
89
89
  - !ruby/object:Gem::Dependency
90
- name: rake
90
+ name: rspec
91
91
  requirement: !ruby/object:Gem::Requirement
92
92
  requirements:
93
93
  - - "~>"
94
94
  - !ruby/object:Gem::Version
95
- version: '11.0'
95
+ version: '3.4'
96
96
  type: :development
97
97
  prerelease: false
98
98
  version_requirements: !ruby/object:Gem::Requirement
99
99
  requirements:
100
100
  - - "~>"
101
101
  - !ruby/object:Gem::Version
102
- version: '11.0'
102
+ version: '3.4'
103
103
  - !ruby/object:Gem::Dependency
104
- name: rspec
104
+ name: simplecov
105
105
  requirement: !ruby/object:Gem::Requirement
106
106
  requirements:
107
- - - "~>"
107
+ - - ">="
108
108
  - !ruby/object:Gem::Version
109
- version: '3.4'
109
+ version: '0'
110
110
  type: :development
111
111
  prerelease: false
112
112
  version_requirements: !ruby/object:Gem::Requirement
113
113
  requirements:
114
- - - "~>"
114
+ - - ">="
115
115
  - !ruby/object:Gem::Version
116
- version: '3.4'
116
+ version: '0'
117
117
  description: Different relational databases treat text search very differently. DbTextSearch
118
118
  provides a unified interface on top of ActiveRecord for SQLite, MySQL, and PostgreSQL
119
119
  to do case-insensitive string-in-set querying and CI index creation, and basic full-text
@@ -128,6 +128,7 @@ files:
128
128
  - CODE_OF_CONDUCT.md
129
129
  - LICENSE.txt
130
130
  - README.md
131
+ - RELEASE-CHECKLIST.md
131
132
  - db_text_search.gemspec
132
133
  - lib/db_text_search.rb
133
134
  - lib/db_text_search/case_insensitive.rb
@@ -142,31 +143,33 @@ files:
142
143
  - lib/db_text_search/full_text/sqlite_adapter.rb
143
144
  - lib/db_text_search/query_building.rb
144
145
  - lib/db_text_search/version.rb
146
+ - rubocop.gemfile
145
147
  - shared.gemfile
146
148
  homepage: https://github.com/thredded/db_text_search
147
149
  licenses:
148
150
  - MIT
149
151
  metadata: {}
150
- post_install_message:
152
+ post_install_message:
151
153
  rdoc_options: []
152
154
  require_paths:
153
155
  - lib
154
156
  required_ruby_version: !ruby/object:Gem::Requirement
155
157
  requirements:
156
- - - "~>"
158
+ - - ">="
157
159
  - !ruby/object:Gem::Version
158
160
  version: '2.1'
161
+ - - "<"
162
+ - !ruby/object:Gem::Version
163
+ version: '4.0'
159
164
  required_rubygems_version: !ruby/object:Gem::Requirement
160
165
  requirements:
161
166
  - - ">="
162
167
  - !ruby/object:Gem::Version
163
168
  version: '0'
164
169
  requirements: []
165
- rubyforge_project:
166
- rubygems_version: 2.5.1
167
- signing_key:
170
+ rubygems_version: 3.2.3
171
+ signing_key:
168
172
  specification_version: 4
169
173
  summary: A unified interface on top of ActiveRecord for SQLite, MySQL, and PostgreSQLfor
170
174
  case-insensitive string search and basic full-text search.
171
175
  test_files: []
172
- has_rdoc: