pg_search 2.3.6 → 2.3.7

Sign up to get free protection for your applications and to get access to all the features.
Files changed (50) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/ci.yml +21 -16
  3. data/.standard.yml +6 -0
  4. data/CHANGELOG.md +11 -0
  5. data/Gemfile +19 -6
  6. data/LICENSE +1 -1
  7. data/README.md +49 -32
  8. data/Rakefile +4 -7
  9. data/lib/pg_search/configuration/column.rb +6 -4
  10. data/lib/pg_search/configuration/foreign_column.rb +1 -1
  11. data/lib/pg_search/configuration.rb +1 -1
  12. data/lib/pg_search/document.rb +8 -8
  13. data/lib/pg_search/features/dmetaphone.rb +1 -1
  14. data/lib/pg_search/features/trigram.rb +4 -4
  15. data/lib/pg_search/features/tsearch.rb +14 -13
  16. data/lib/pg_search/migration/dmetaphone_generator.rb +2 -2
  17. data/lib/pg_search/migration/generator.rb +5 -5
  18. data/lib/pg_search/migration/multisearch_generator.rb +2 -2
  19. data/lib/pg_search/model.rb +6 -6
  20. data/lib/pg_search/multisearch.rb +4 -2
  21. data/lib/pg_search/multisearchable.rb +7 -7
  22. data/lib/pg_search/normalizer.rb +5 -5
  23. data/lib/pg_search/scope_options.rb +26 -5
  24. data/lib/pg_search/tasks.rb +2 -2
  25. data/lib/pg_search/version.rb +1 -1
  26. data/lib/pg_search.rb +3 -3
  27. data/pg_search.gemspec +16 -31
  28. data/spec/.rubocop.yml +20 -7
  29. data/spec/integration/.rubocop.yml +2 -2
  30. data/spec/integration/associations_spec.rb +106 -106
  31. data/spec/integration/deprecation_spec.rb +7 -8
  32. data/spec/integration/pg_search_spec.rb +314 -298
  33. data/spec/integration/single_table_inheritance_spec.rb +5 -5
  34. data/spec/lib/pg_search/configuration/association_spec.rb +15 -15
  35. data/spec/lib/pg_search/configuration/column_spec.rb +13 -1
  36. data/spec/lib/pg_search/configuration/foreign_column_spec.rb +4 -4
  37. data/spec/lib/pg_search/features/dmetaphone_spec.rb +4 -4
  38. data/spec/lib/pg_search/features/trigram_spec.rb +29 -29
  39. data/spec/lib/pg_search/features/tsearch_spec.rb +57 -39
  40. data/spec/lib/pg_search/multisearch/rebuilder_spec.rb +17 -17
  41. data/spec/lib/pg_search/multisearch_spec.rb +6 -6
  42. data/spec/lib/pg_search/multisearchable_spec.rb +26 -26
  43. data/spec/lib/pg_search/normalizer_spec.rb +7 -7
  44. data/spec/lib/pg_search_spec.rb +18 -18
  45. data/spec/spec_helper.rb +7 -9
  46. data/spec/support/database.rb +6 -6
  47. metadata +10 -214
  48. data/.codeclimate.yml +0 -17
  49. data/.rubocop.yml +0 -137
  50. data/.travis.yml +0 -37
@@ -7,9 +7,11 @@ module PgSearch
7
7
  class << self
8
8
  def rebuild(model, deprecated_clean_up = nil, clean_up: true, transactional: true)
9
9
  unless deprecated_clean_up.nil?
10
- ActiveSupport::Deprecation.warn(
10
+ warn(
11
11
  "pg_search 3.0 will no longer accept a boolean second argument to PgSearchMultisearch.rebuild, " \
12
- "use keyword argument `clean_up:` instead."
12
+ "use keyword argument `clean_up:` instead.",
13
+ category: :deprecated,
14
+ uplevel: 1
13
15
  )
14
16
  clean_up = deprecated_clean_up
15
17
  end
@@ -7,12 +7,12 @@ module PgSearch
7
7
  def self.included(mod)
8
8
  mod.class_eval do
9
9
  has_one :pg_search_document,
10
- as: :searchable,
11
- class_name: "PgSearch::Document",
12
- dependent: :delete
10
+ as: :searchable,
11
+ class_name: "PgSearch::Document",
12
+ dependent: :delete
13
13
 
14
14
  after_save :update_pg_search_document,
15
- if: -> { PgSearch.multisearch_enabled? }
15
+ if: -> { PgSearch.multisearch_enabled? }
16
16
  end
17
17
  end
18
18
 
@@ -39,7 +39,7 @@ module PgSearch
39
39
  conditions.all? { |condition| condition.to_proc.call(self) }
40
40
  end
41
41
 
42
- def update_pg_search_document # rubocop:disable Metrics/AbcSize
42
+ def update_pg_search_document
43
43
  if_conditions = Array(pg_search_multisearchable_options[:if])
44
44
  unless_conditions = Array(pg_search_multisearchable_options[:unless])
45
45
 
@@ -50,7 +50,7 @@ module PgSearch
50
50
  if should_have_document
51
51
  create_or_update_pg_search_document
52
52
  else
53
- pg_search_document&.destroy
53
+ pg_search_document&.destroy # standard:disable Rails/SaveBang
54
54
  end
55
55
  end
56
56
 
@@ -58,7 +58,7 @@ module PgSearch
58
58
  if !pg_search_document
59
59
  create_pg_search_document(pg_search_document_attrs)
60
60
  elsif should_update_pg_search_document?
61
- pg_search_document.update(pg_search_document_attrs)
61
+ pg_search_document.update(pg_search_document_attrs) # standard:disable Rails/SaveBang
62
62
  end
63
63
  end
64
64
  end
@@ -10,11 +10,11 @@ module PgSearch
10
10
  return sql_expression unless config.ignore.include?(:accents)
11
11
 
12
12
  sql_node = case sql_expression
13
- when Arel::Nodes::Node
14
- sql_expression
15
- else
16
- Arel.sql(sql_expression)
17
- end
13
+ when Arel::Nodes::Node
14
+ sql_expression
15
+ else
16
+ Arel.sql(sql_expression)
17
+ end
18
18
 
19
19
  Arel::Nodes::NamedFunction.new(
20
20
  PgSearch.unaccent_function,
@@ -90,11 +90,32 @@ module PgSearch
90
90
  end
91
91
 
92
92
  def conditions
93
- config.features
94
- .reject { |_feature_name, feature_options| feature_options && feature_options[:sort_only] }
95
- .map { |feature_name, _feature_options| feature_for(feature_name).conditions }
96
- .inject { |accumulator, expression| Arel::Nodes::Or.new(accumulator, expression) }
93
+ expressions =
94
+ config.features
95
+ .reject { |_feature_name, feature_options| feature_options && feature_options[:sort_only] }
96
+ .map { |feature_name, _feature_options| feature_for(feature_name).conditions }
97
+
98
+ or_node(expressions)
99
+ end
100
+
101
+ # https://github.com/rails/rails/pull/51492
102
+ # :nocov:
103
+ # standard:disable Lint/DuplicateMethods
104
+ or_arity = Arel::Nodes::Or.instance_method(:initialize).arity
105
+ case or_arity
106
+ when 1
107
+ def or_node(expressions)
108
+ Arel::Nodes::Or.new(expressions)
109
+ end
110
+ when 2
111
+ def or_node(expressions)
112
+ expressions.inject { |accumulator, expression| Arel::Nodes::Or.new(accumulator, expression) }
113
+ end
114
+ else
115
+ raise "Unsupported arity #{or_arity} for Arel::Nodes::Or#initialize"
97
116
  end
117
+ # :nocov:
118
+ # standard:enable Lint/DuplicateMethods
98
119
 
99
120
  def order_within_rank
100
121
  config.order_within_rank || "#{primary_key} ASC"
@@ -108,7 +129,7 @@ module PgSearch
108
129
  if config.associations.any?
109
130
  config.associations.map do |association|
110
131
  association.join(primary_key)
111
- end.join(' ')
132
+ end.join(" ")
112
133
  end
113
134
  end
114
135
 
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'rake'
4
- require 'pg_search'
3
+ require "rake"
4
+ require "pg_search"
5
5
 
6
6
  namespace :pg_search do
7
7
  namespace :multisearch do
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module PgSearch
4
- VERSION = '2.3.6'
4
+ VERSION = "2.3.7"
5
5
  end
data/lib/pg_search.rb CHANGED
@@ -18,7 +18,7 @@ module PgSearch
18
18
  autoload :Document, "pg_search/document"
19
19
 
20
20
  def self.included(base)
21
- ActiveSupport::Deprecation.warn <<~MESSAGE
21
+ warn(<<~MESSAGE, category: :deprecated, uplevel: 1)
22
22
  Directly including `PgSearch` into an Active Record model is deprecated and will be removed in pg_search 3.0.
23
23
 
24
24
  Please replace `include PgSearch` with `include PgSearch::Model`.
@@ -34,8 +34,8 @@ module PgSearch
34
34
  self.unaccent_function = "unaccent"
35
35
 
36
36
  class << self
37
- def multisearch(*args)
38
- PgSearch::Document.search(*args)
37
+ def multisearch(...)
38
+ PgSearch::Document.search(...)
39
39
  end
40
40
 
41
41
  def disable_multisearch
data/pg_search.gemspec CHANGED
@@ -1,40 +1,25 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- $LOAD_PATH.push File.expand_path('lib', __dir__)
4
- require 'pg_search/version'
3
+ $LOAD_PATH.push File.expand_path("lib", __dir__)
4
+ require "pg_search/version"
5
5
 
6
- Gem::Specification.new do |s| # rubocop:disable Metrics/BlockLength
7
- s.name = 'pg_search'
8
- s.version = PgSearch::VERSION
9
- s.platform = Gem::Platform::RUBY
10
- s.authors = ['Grant Hutchins', 'Case Commons, LLC']
11
- s.email = %w[gems@nertzy.com casecommons-dev@googlegroups.com]
12
- s.homepage = 'https://github.com/Casecommons/pg_search'
13
- s.summary = "PgSearch builds Active Record named scopes that take advantage of PostgreSQL's full text search"
6
+ Gem::Specification.new do |s|
7
+ s.name = "pg_search"
8
+ s.version = PgSearch::VERSION
9
+ s.platform = Gem::Platform::RUBY
10
+ s.authors = ["Grant Hutchins", "Case Commons, LLC"]
11
+ s.email = %w[gems@nertzy.com casecommons-dev@googlegroups.com]
12
+ s.homepage = "https://github.com/Casecommons/pg_search"
13
+ s.summary = "PgSearch builds Active Record named scopes that take advantage of PostgreSQL's full text search"
14
14
  s.description = "PgSearch builds Active Record named scopes that take advantage of PostgreSQL's full text search"
15
- s.licenses = ['MIT']
15
+ s.licenses = ["MIT"]
16
16
  s.metadata["rubygems_mfa_required"] = "true"
17
17
 
18
- s.files = `git ls-files`.split("\n")
19
- s.test_files = `git ls-files -- spec/*`.split("\n")
20
- s.require_paths = ['lib']
18
+ s.files = `git ls-files -z`.split("\x0")
19
+ s.require_paths = ["lib"]
21
20
 
22
- s.add_dependency 'activerecord', '>= 5.2'
23
- s.add_dependency 'activesupport', '>= 5.2'
21
+ s.add_dependency "activerecord", ">= 6.1"
22
+ s.add_dependency "activesupport", ">= 6.1"
24
23
 
25
- s.add_development_dependency 'pry'
26
- s.add_development_dependency 'rake'
27
- s.add_development_dependency 'rspec'
28
- s.add_development_dependency 'rubocop'
29
- s.add_development_dependency 'rubocop-performance'
30
- s.add_development_dependency 'rubocop-rails'
31
- s.add_development_dependency 'rubocop-rake'
32
- s.add_development_dependency 'rubocop-rspec'
33
- s.add_development_dependency 'simplecov'
34
- s.add_development_dependency 'simplecov-lcov'
35
- s.add_development_dependency 'undercover'
36
- s.add_development_dependency 'warning'
37
- s.add_development_dependency 'with_model'
38
-
39
- s.required_ruby_version = '>= 2.6'
24
+ s.required_ruby_version = ">= 3.0"
40
25
  end
data/spec/.rubocop.yml CHANGED
@@ -1,14 +1,27 @@
1
1
  inherit_from:
2
2
  - ../.rubocop.yml
3
3
 
4
- Layout/LineLength:
5
- Enabled: false
4
+ RSpec/ContextWording:
5
+ Prefixes:
6
+ - using
7
+ - via
8
+ - when
9
+ - with
10
+ - without
6
11
 
7
- Lint/SuppressedException:
8
- Enabled: false
12
+ RSpec/DescribedClass:
13
+ Enabled: true
9
14
 
10
- Lint/UselessAssignment:
11
- Enabled: false
15
+ RSpec/ExampleLength:
16
+ Max: 15
12
17
 
13
- Style/BlockDelimiters:
18
+ RSpec/ExpectInHook:
14
19
  Enabled: false
20
+
21
+ RSpec/FilePath:
22
+ CustomTransform:
23
+ TSearch: "tsearch"
24
+ DMetaphone: "dmetaphone"
25
+
26
+ RSpec/MultipleExpectations:
27
+ Max: 5
@@ -4,8 +4,8 @@ inherit_from:
4
4
  RSpec/DescribeClass:
5
5
  Enabled: false
6
6
 
7
- RSpec/MultipleExpectations:
7
+ RSpec/ExampleLength:
8
8
  Enabled: false
9
9
 
10
- RSpec/ExampleLength:
10
+ RSpec/MultipleExpectations:
11
11
  Enabled: false