pg_search 2.1.0 → 2.1.1

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
  SHA1:
3
- metadata.gz: e78424399f49c900c5be4aeb3d427323a8d5cb08
4
- data.tar.gz: 5516d8fcc707711c41ebacff2cf013e04a3d0843
3
+ metadata.gz: 253c1319e785dfac16b15e9ffc72d7d37b60eda5
4
+ data.tar.gz: 78931e1fac31befac51f12b5ae2c26c13a11994a
5
5
  SHA512:
6
- metadata.gz: 2b953933148c7c760047cc7ef8d0d88ff1b6f5f79a5fde5899091a7eb8153e5df7162bda5bbac19304d2188f20564bff1da443551db0e7a23de17c27c66a5bc2
7
- data.tar.gz: b8507bbc4567a7eedb31fbe9f7bf9f8412360efc1b4a5e52410425f9f59cb5e5f69c40e53c65e3c7789eca00412ffc9c7a04b90cecc320f4a877fd47154d12dc
6
+ metadata.gz: 53f22f8135d1992271bae14aa8b77cc76fd75d625b60c01075157383f9716c3aee9e1bf6e404e79b21cdbb0a7e611c9b820e3553a05485ba485f3b404a2afa28
7
+ data.tar.gz: 768c5c7a66b4875cce05f12b4e0bbe50ddd8dc8a6bd3afdcb2acf9db2334ffe1ad1d04d99814a0bf38876a7829320faeda5227886a13b5c81720a33d7438223b
@@ -34,7 +34,7 @@ Style/PercentLiteralDelimiters:
34
34
  Style/GuardClause:
35
35
  Enabled: false
36
36
 
37
- Style/VariableNumber:
37
+ Naming/VariableNumber:
38
38
  EnforcedStyle: snake_case
39
39
 
40
40
  Bundler/OrderedGems:
@@ -1,5 +1,9 @@
1
1
  # pg_search changelog
2
2
 
3
+ ## 2.1.1
4
+
5
+ * Support snake_case ts_headline options again (with deprecation warning)
6
+
3
7
  ## 2.1.0
4
8
 
5
9
  * Allow ts_headline options to be passed to :highlight (Ian Heisters)
@@ -1,4 +1,5 @@
1
1
  require "active_support/core_ext/module/delegation"
2
+ require 'active_support/deprecation'
2
3
 
3
4
  module PgSearch
4
5
  module Features
@@ -35,11 +36,14 @@ module PgSearch
35
36
  def ts_headline_options
36
37
  return '' unless options[:highlight].is_a?(Hash)
37
38
 
38
- headline_options = map_headline_options
39
- headline_options.map { |key, value| "#{key} = #{value}" unless value.nil? }.compact.join(", ")
39
+ headline_options
40
+ .merge(deprecated_headline_options)
41
+ .map { |key, value| "#{key} = #{value}" unless value.nil? }
42
+ .compact
43
+ .join(", ")
40
44
  end
41
45
 
42
- def map_headline_options
46
+ def headline_options
43
47
  indifferent_options = options.with_indifferent_access
44
48
 
45
49
  %w[
@@ -48,20 +52,47 @@ module PgSearch
48
52
  hash.tap do
49
53
  value = indifferent_options[:highlight][key]
50
54
 
51
- hash[key] = case value
52
- when String
53
- %("#{value.gsub('"', '""')}")
54
- when true
55
- "TRUE"
56
- when false
57
- "FALSE"
58
- else
59
- value
60
- end
55
+ hash[key] = ts_headline_option_value(value)
61
56
  end
62
57
  end
63
58
  end
64
59
 
60
+ def deprecated_headline_options
61
+ indifferent_options = options.with_indifferent_access
62
+
63
+ %w[
64
+ start_sel stop_sel max_fragments max_words min_words short_word fragment_delimiter highlight_all
65
+ ].reduce({}) do |hash, deprecated_key|
66
+ hash.tap do
67
+ value = indifferent_options[:highlight][deprecated_key]
68
+
69
+ unless value.nil?
70
+ key = deprecated_key.camelize
71
+
72
+ ActiveSupport::Deprecation.warn(
73
+ "pg_search 3.0 will no longer accept :#{deprecated_key} as an argument to :ts_headline, " \
74
+ "use :#{key} instead."
75
+ )
76
+
77
+ hash[key] = ts_headline_option_value(value)
78
+ end
79
+ end
80
+ end
81
+ end
82
+
83
+ def ts_headline_option_value(value)
84
+ case value
85
+ when String
86
+ %("#{value.gsub('"', '""')}")
87
+ when true
88
+ "TRUE"
89
+ when false
90
+ "FALSE"
91
+ else
92
+ value
93
+ end
94
+ end
95
+
65
96
  DISALLOWED_TSQUERY_CHARACTERS = /['?\\:]/
66
97
 
67
98
  def tsquery_for_term(unsanitized_term) # rubocop:disable Metrics/AbcSize
@@ -1,5 +1,3 @@
1
- # encoding: UTF-8
2
-
3
1
  require "active_support/core_ext/module/delegation"
4
2
 
5
3
  module PgSearch
@@ -1,3 +1,3 @@
1
1
  module PgSearch
2
- VERSION = "2.1.0".freeze
2
+ VERSION = "2.1.1".freeze
3
3
  end
@@ -1,5 +1,3 @@
1
- # -*- encoding: utf-8 -*-
2
-
3
1
  $LOAD_PATH.push File.expand_path('../lib', __FILE__)
4
2
  require 'pg_search/version'
5
3
 
@@ -48,7 +48,7 @@ describe PgSearch::Configuration::Association do
48
48
 
49
49
  describe "#join" do
50
50
  let(:expected_sql) do
51
- <<-EOS.gsub(/\s+/, ' ').strip
51
+ <<-SQL.gsub(/\s+/, ' ').strip
52
52
  LEFT OUTER JOIN
53
53
  (SELECT model_id AS id,
54
54
  #{column_select} AS #{association.columns.first.alias}
@@ -56,7 +56,7 @@ describe PgSearch::Configuration::Association do
56
56
  INNER JOIN \"#{association.table_name}\"
57
57
  ON \"#{association.table_name}\".\"user_id\" = \"#{User.table_name}\".\"id\") #{association.subselect_alias}
58
58
  ON #{association.subselect_alias}.id = model_id
59
- EOS
59
+ SQL
60
60
  end
61
61
  let(:column_select) do
62
62
  "\"#{association.table_name}\".\"url\"::text"
@@ -79,7 +79,7 @@ describe PgSearch::Configuration::Association do
79
79
 
80
80
  describe "#join" do
81
81
  let(:expected_sql) do
82
- <<-EOS.gsub(/\s+/, ' ').strip
82
+ <<-SQL.gsub(/\s+/, ' ').strip
83
83
  LEFT OUTER JOIN
84
84
  (SELECT model_id AS id,
85
85
  #{column_select} AS #{association.columns.first.alias}
@@ -87,7 +87,7 @@ describe PgSearch::Configuration::Association do
87
87
  INNER JOIN \"#{association.table_name}\"
88
88
  ON \"#{association.table_name}\".\"id\" = \"#{User.table_name}\".\"site_id\") #{association.subselect_alias}
89
89
  ON #{association.subselect_alias}.id = model_id
90
- EOS
90
+ SQL
91
91
  end
92
92
  let(:column_select) do
93
93
  "\"#{association.table_name}\".\"title\"::text"
@@ -110,7 +110,7 @@ describe PgSearch::Configuration::Association do
110
110
 
111
111
  describe "#join" do
112
112
  let(:expected_sql) do
113
- <<-EOS.gsub(/\s+/, ' ').strip
113
+ <<-SQL.gsub(/\s+/, ' ').strip
114
114
  LEFT OUTER JOIN
115
115
  (SELECT model_id AS id,
116
116
  string_agg(\"#{association.table_name}\".\"name\"::text, ' ') AS #{association.columns.first.alias}
@@ -119,7 +119,7 @@ describe PgSearch::Configuration::Association do
119
119
  ON \"#{association.table_name}\".\"site_id\" = \"#{Site.table_name}\".\"id\"
120
120
  GROUP BY model_id) #{association.subselect_alias}
121
121
  ON #{association.subselect_alias}.id = model_id
122
- EOS
122
+ SQL
123
123
  end
124
124
 
125
125
  it "returns the correct SQL join" do
@@ -1,4 +1,5 @@
1
1
  require "spec_helper"
2
+ require "active_support/deprecation"
2
3
 
3
4
  describe PgSearch::Features::TSearch do
4
5
  describe "#rank" do
@@ -201,6 +202,35 @@ describe PgSearch::Features::TSearch do
201
202
 
202
203
  expect(feature.highlight.to_sql).to eq(expected_sql)
203
204
  end
205
+
206
+ it "passes deprecated options to ts_headline" do
207
+ query = "query"
208
+ columns = [
209
+ PgSearch::Configuration::Column.new(:name, nil, Model)
210
+ ]
211
+ options = {
212
+ highlight: {
213
+ start_sel: '<start class="search">',
214
+ stop_sel: '<stop>',
215
+ max_words: 123,
216
+ min_words: 456,
217
+ short_word: 4,
218
+ highlight_all: false,
219
+ max_fragments: 3,
220
+ fragment_delimiter: '&hellip;'
221
+ }
222
+ }
223
+
224
+ config = double(:config, :ignore => [])
225
+ normalizer = PgSearch::Normalizer.new(config)
226
+
227
+ feature = described_class.new(query, options, columns, Model, normalizer)
228
+
229
+ highlight_sql = ActiveSupport::Deprecation.silence { feature.highlight.to_sql }
230
+ expected_sql = %{(ts_headline('simple', (coalesce(#{Model.quoted_table_name}."name"::text, '')), (to_tsquery('simple', ''' ' || 'query' || ' ''')), 'StartSel = "<start class=""search"">", StopSel = "<stop>", MaxFragments = 3, MaxWords = 123, MinWords = 456, ShortWord = 4, FragmentDelimiter = "&hellip;", HighlightAll = FALSE'))}
231
+
232
+ expect(highlight_sql).to eq(expected_sql)
233
+ end
204
234
  end
205
235
  end
206
236
  end
@@ -223,7 +223,7 @@ describe PgSearch do
223
223
  @multisearch_enabled_inside = PgSearch.multisearch_enabled?
224
224
  raise
225
225
  end
226
- rescue
226
+ rescue # rubocop:disable Lint/RescueWithoutErrorClass
227
227
  end
228
228
 
229
229
  @multisearch_enabled_after = PgSearch.multisearch_enabled?
@@ -42,7 +42,7 @@ def install_extension(name)
42
42
  extension = connection.execute "SELECT * FROM pg_catalog.pg_extension WHERE extname = '#{name}';"
43
43
  return unless extension.none?
44
44
  connection.execute "CREATE EXTENSION #{name};"
45
- rescue => exception
45
+ rescue => exception # rubocop:disable Lint/RescueWithoutErrorClass
46
46
  at_exit do
47
47
  puts "-" * 80
48
48
  puts "Please install the #{name} extension"
@@ -54,7 +54,7 @@ end
54
54
  def install_extension_if_missing(name, query, expected_result)
55
55
  result = ActiveRecord::Base.connection.select_value(query)
56
56
  raise "Unexpected output for #{query}: #{result.inspect}" unless result.downcase == expected_result.downcase
57
- rescue
57
+ rescue # rubocop:disable Lint/RescueWithoutErrorClass
58
58
  install_extension(name)
59
59
  end
60
60
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pg_search
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.0
4
+ version: 2.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Grant Hutchins
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2017-07-29 00:00:00.000000000 Z
12
+ date: 2017-09-20 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activerecord
@@ -241,7 +241,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
241
241
  version: '0'
242
242
  requirements: []
243
243
  rubyforge_project:
244
- rubygems_version: 2.6.8
244
+ rubygems_version: 2.5.1
245
245
  signing_key:
246
246
  specification_version: 4
247
247
  summary: PgSearch builds Active Record named scopes that take advantage of PostgreSQL's