algolia 2.0.0.pre.beta.2 → 2.0.0.pre.beta.3

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: 4645e42bf97d367a91ac73d59c440bc8f07d34c969df2d16ca3d6fac652f14f9
4
- data.tar.gz: 2188142202397e4e56dbe7b77d635b439794ebf6401472e83907ab078e593a45
3
+ metadata.gz: 47d18253040f91e77f82a815e90b4064c88aac2ddbacbe4c26b1dea81304d847
4
+ data.tar.gz: 530b601d76e6de0b4f252dc13bcce01f7446428f839cd22fb4b286a1b5a17f73
5
5
  SHA512:
6
- metadata.gz: edb4691eaa9e505a1e014e58232edffb0c6fdb62686f52b90c597b037392e81c1af98c7e339f017ad5b1ecab916d07336cf31c734832838d7648fcab82e2fe82
7
- data.tar.gz: c9d8da55b0599118d3153ca84e1bf34f909cf128c101b5480ffff64213253e45685daef451ee48e15410737319efd6dea5f75768b3e2c0af0947160b1304473e
6
+ metadata.gz: 04c63a1fb49fcd66817e0b43f66c16b3cbe8bd044ca513409047f8709ab8cc757deb30cedaeafcddf831f98179efa9c21fdcbf4bb09a1641b9b5b7aa96d6fc8c
7
+ data.tar.gz: e552093cc4ab5827c8ab87e448856bfdbd68f113b8e321e928e66ceb03f8ecf96531aad902d256a6372336c9efeedd166e85165d63a0c83f0795de942a0b4eb7
@@ -3,7 +3,7 @@ require 'faraday'
3
3
  module Algolia
4
4
  class BaseConfig
5
5
  attr_accessor :app_id, :api_key, :headers, :batch_size, :read_timeout, :write_timeout, :connect_timeout, :compression_type,
6
- :symbolize_keys
6
+ :symbolize_keys, :use_latest_settings
7
7
 
8
8
  #
9
9
  # @option options [String] :application_id
@@ -28,12 +28,14 @@ module Algolia
28
28
  'User-Agent' => UserAgent.value
29
29
  }
30
30
 
31
- @batch_size = opts[:batch_size] || Defaults::BATCH_SIZE
32
- @read_timeout = opts[:read_timeout] || Defaults::READ_TIMEOUT
33
- @write_timeout = opts[:write_timeout] || Defaults::WRITE_TIMEOUT
34
- @connect_timeout = opts[:connect_timeout] || Defaults::CONNECT_TIMEOUT
35
- @compression_type = opts[:compression_type] || Defaults::NONE_ENCODING
36
- @symbolize_keys = opts.has_key?(:symbolize_keys) ? opts[:symbolize_keys] : true
31
+ @batch_size = opts[:batch_size] || Defaults::BATCH_SIZE
32
+ @read_timeout = opts[:read_timeout] || Defaults::READ_TIMEOUT
33
+ @write_timeout = opts[:write_timeout] || Defaults::WRITE_TIMEOUT
34
+ @connect_timeout = opts[:connect_timeout] || Defaults::CONNECT_TIMEOUT
35
+ @compression_type = opts[:compression_type] || Defaults::NONE_ENCODING
36
+ @symbolize_keys = opts.has_key?(:symbolize_keys) ? opts[:symbolize_keys] : true
37
+ # used to avoid BC break on Rails integration, should not be documented
38
+ @use_latest_settings = opts.has_key?(:use_latest_settings) ? opts[:use_latest_settings] : true
37
39
  end
38
40
 
39
41
  def set_extra_header(key, value)
@@ -52,7 +52,9 @@ module Helpers
52
52
 
53
53
  # Support to convert old settings to their new names
54
54
  #
55
- def deserialize_settings(data)
55
+ def deserialize_settings(data, use_latest_settings, symbolize_keys)
56
+ return data unless use_latest_settings
57
+
56
58
  settings = symbolize_hash(data)
57
59
  keys = {
58
60
  attributesToIndex: 'searchableAttributes',
@@ -62,7 +64,8 @@ module Helpers
62
64
 
63
65
  keys.each do |deprecated_key, current_key|
64
66
  if settings.has_key?(deprecated_key)
65
- settings[current_key.to_sym] = settings.delete(deprecated_key)
67
+ key = symbolize_keys ? current_key.to_sym : current_key.to_s
68
+ settings[key] = settings.delete(deprecated_key)
66
69
  end
67
70
  end
68
71
 
@@ -976,7 +976,7 @@ module Algolia
976
976
  def get_settings(opts = {})
977
977
  response = @transporter.read(:GET, path_encode('/1/indexes/%s/settings', @name) + handle_params({ getVersion: 2 }), {}, opts)
978
978
 
979
- deserialize_settings(response)
979
+ deserialize_settings(response, @config.use_latest_settings, @config.symbolize_keys)
980
980
  end
981
981
 
982
982
  # Update some index settings. Only specified settings are overridden
@@ -1,3 +1,3 @@
1
1
  module Algolia
2
- VERSION = '2.0.0-beta.2'.freeze
2
+ VERSION = '2.0.0-beta.3'.freeze
3
3
  end
@@ -18,7 +18,35 @@ class HelpersTest
18
18
  replicas: %w(index1 index2)
19
19
  }
20
20
 
21
- deserialized_settings = deserialize_settings(old_settings)
21
+ deserialized_settings = deserialize_settings(old_settings, true, true)
22
+ assert_equal new_settings, deserialized_settings
23
+ end
24
+
25
+ def test_deserialize_settings_with_old_settings
26
+ old_settings = {
27
+ attributesToIndex: %w(attr1 attr2),
28
+ numericAttributesToIndex: %w(attr1 attr2),
29
+ slaves: %w(index1 index2)
30
+ }
31
+
32
+ deserialized_settings = deserialize_settings(old_settings, false, true)
33
+ assert_equal old_settings, deserialized_settings
34
+ end
35
+
36
+ def test_deserialize_settings_with_string
37
+ old_settings = {
38
+ 'attributesToIndex' => %w(attr1 attr2),
39
+ 'numericAttributesToIndex' => %w(attr1 attr2),
40
+ 'slaves' => %w(index1 index2)
41
+ }
42
+
43
+ new_settings = {
44
+ 'searchableAttributes' => %w(attr1 attr2),
45
+ 'numericAttributesForFiltering' => %w(attr1 attr2),
46
+ 'replicas' => %w(index1 index2)
47
+ }
48
+
49
+ deserialized_settings = deserialize_settings(old_settings, true, false)
22
50
  assert_equal new_settings, deserialized_settings
23
51
  end
24
52
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: algolia
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.0.pre.beta.2
4
+ version: 2.0.0.pre.beta.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Algolia
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-10-19 00:00:00.000000000 Z
11
+ date: 2020-10-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler