chewy 0.6.2 → 0.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (101) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +2 -1
  3. data/.travis.yml +35 -29
  4. data/Appraisals +37 -0
  5. data/CHANGELOG.md +115 -4
  6. data/Gemfile +2 -3
  7. data/README.md +135 -40
  8. data/chewy.gemspec +4 -3
  9. data/gemfiles/rails.3.2.activerecord.gemfile +13 -0
  10. data/gemfiles/rails.3.2.activerecord.kaminari.gemfile +14 -0
  11. data/gemfiles/rails.3.2.activerecord.will_paginate.gemfile +14 -0
  12. data/gemfiles/rails.4.0.activerecord.gemfile +13 -0
  13. data/gemfiles/rails.4.0.activerecord.kaminari.gemfile +14 -0
  14. data/gemfiles/rails.4.0.activerecord.will_paginate.gemfile +14 -0
  15. data/gemfiles/rails.4.0.mongoid.gemfile +13 -0
  16. data/gemfiles/rails.4.0.mongoid.kaminari.gemfile +14 -0
  17. data/gemfiles/rails.4.0.mongoid.will_paginate.gemfile +14 -0
  18. data/gemfiles/rails.4.1.activerecord.gemfile +13 -0
  19. data/gemfiles/rails.4.1.activerecord.kaminari.gemfile +14 -0
  20. data/gemfiles/rails.4.1.activerecord.will_paginate.gemfile +14 -0
  21. data/gemfiles/rails.4.1.mongoid.gemfile +13 -0
  22. data/gemfiles/rails.4.1.mongoid.kaminari.gemfile +14 -0
  23. data/gemfiles/rails.4.1.mongoid.will_paginate.gemfile +14 -0
  24. data/gemfiles/rails.4.2.activerecord.gemfile +13 -0
  25. data/gemfiles/rails.4.2.activerecord.kaminari.gemfile +14 -0
  26. data/gemfiles/rails.4.2.activerecord.will_paginate.gemfile +14 -0
  27. data/gemfiles/rails.4.2.mongoid.gemfile +13 -0
  28. data/gemfiles/rails.4.2.mongoid.kaminari.gemfile +14 -0
  29. data/gemfiles/rails.4.2.mongoid.will_paginate.gemfile +14 -0
  30. data/lib/chewy.rb +65 -0
  31. data/lib/chewy/config.rb +44 -93
  32. data/lib/chewy/errors.rb +14 -5
  33. data/lib/chewy/fields/base.rb +8 -7
  34. data/lib/chewy/fields/root.rb +2 -2
  35. data/lib/chewy/index.rb +7 -9
  36. data/lib/chewy/log_subscriber.rb +34 -0
  37. data/lib/chewy/query.rb +41 -27
  38. data/lib/chewy/query/criteria.rb +28 -23
  39. data/lib/chewy/query/scoping.rb +20 -0
  40. data/lib/chewy/railtie.rb +51 -13
  41. data/lib/chewy/repository.rb +61 -0
  42. data/lib/chewy/rspec/update_index.rb +3 -6
  43. data/lib/chewy/search.rb +28 -7
  44. data/lib/chewy/strategy.rb +60 -0
  45. data/lib/chewy/strategy/atomic.rb +31 -0
  46. data/lib/chewy/strategy/base.rb +27 -0
  47. data/lib/chewy/strategy/bypass.rb +15 -0
  48. data/lib/chewy/strategy/urgent.rb +17 -0
  49. data/lib/chewy/type.rb +19 -5
  50. data/lib/chewy/type/adapter/active_record.rb +28 -117
  51. data/lib/chewy/type/adapter/base.rb +35 -0
  52. data/lib/chewy/type/adapter/mongoid.rb +23 -123
  53. data/lib/chewy/type/adapter/object.rb +41 -19
  54. data/lib/chewy/type/adapter/orm.rb +142 -0
  55. data/lib/chewy/type/import.rb +43 -16
  56. data/lib/chewy/type/observe.rb +8 -21
  57. data/lib/chewy/version.rb +1 -1
  58. data/lib/tasks/chewy.rake +8 -4
  59. data/spec/chewy/config_spec.rb +20 -97
  60. data/spec/chewy/fields/base_spec.rb +24 -11
  61. data/spec/chewy/fields/time_fields_spec.rb +27 -0
  62. data/spec/chewy/index/settings_spec.rb +2 -1
  63. data/spec/chewy/index_spec.rb +98 -79
  64. data/spec/chewy/query/criteria_spec.rb +14 -0
  65. data/spec/chewy/query_spec.rb +1 -1
  66. data/spec/chewy/repository_spec.rb +50 -0
  67. data/spec/chewy/search_spec.rb +100 -0
  68. data/spec/chewy/strategy_spec.rb +109 -0
  69. data/spec/chewy/type/adapter/active_record_spec.rb +110 -46
  70. data/spec/chewy/type/adapter/mongoid_spec.rb +123 -74
  71. data/spec/chewy/type/adapter/object_spec.rb +51 -34
  72. data/spec/chewy/type/import_spec.rb +21 -21
  73. data/spec/chewy/type/observe_spec.rb +26 -29
  74. data/spec/chewy/type_spec.rb +19 -0
  75. data/spec/chewy_spec.rb +19 -3
  76. data/spec/spec_helper.rb +1 -1
  77. data/spec/support/active_record.rb +2 -1
  78. data/spec/support/mongoid.rb +29 -38
  79. metadata +85 -55
  80. data/gemfiles/Gemfile.rails-3.2.active_record +0 -6
  81. data/gemfiles/Gemfile.rails-3.2.active_record.kaminari +0 -7
  82. data/gemfiles/Gemfile.rails-3.2.active_record.will_paginate +0 -7
  83. data/gemfiles/Gemfile.rails-4.0.active_record +0 -6
  84. data/gemfiles/Gemfile.rails-4.0.active_record.kaminari +0 -7
  85. data/gemfiles/Gemfile.rails-4.0.active_record.will_paginate +0 -7
  86. data/gemfiles/Gemfile.rails-4.0.mongoid +0 -6
  87. data/gemfiles/Gemfile.rails-4.0.mongoid.kaminari +0 -7
  88. data/gemfiles/Gemfile.rails-4.0.mongoid.will_paginate +0 -7
  89. data/gemfiles/Gemfile.rails-4.1.active_record +0 -6
  90. data/gemfiles/Gemfile.rails-4.1.active_record.kaminari +0 -7
  91. data/gemfiles/Gemfile.rails-4.1.active_record.will_paginate +0 -7
  92. data/gemfiles/Gemfile.rails-4.1.mongoid +0 -6
  93. data/gemfiles/Gemfile.rails-4.1.mongoid.kaminari +0 -7
  94. data/gemfiles/Gemfile.rails-4.1.mongoid.will_paginate +0 -7
  95. data/gemfiles/Gemfile.rails-4.2.active_record +0 -6
  96. data/gemfiles/Gemfile.rails-4.2.active_record.kaminari +0 -7
  97. data/gemfiles/Gemfile.rails-4.2.active_record.will_paginate +0 -7
  98. data/gemfiles/Gemfile.rails-4.2.mongoid +0 -6
  99. data/gemfiles/Gemfile.rails-4.2.mongoid.kaminari +0 -7
  100. data/gemfiles/Gemfile.rails-4.2.mongoid.will_paginate +0 -7
  101. data/spec/chewy/index/search_spec.rb +0 -46
@@ -19,11 +19,12 @@ Gem::Specification.new do |spec|
19
19
  spec.require_paths = ['lib']
20
20
 
21
21
  spec.add_development_dependency 'rake'
22
- spec.add_development_dependency 'rspec', '~> 3.0.0'
23
- spec.add_development_dependency 'rspec-its', '~> 1.0.1'
22
+ spec.add_development_dependency 'appraisal'
23
+ spec.add_development_dependency 'rspec'
24
+ spec.add_development_dependency 'rspec-its'
24
25
  spec.add_development_dependency 'rspec-collection_matchers'
25
26
  spec.add_development_dependency 'sqlite3'
26
- spec.add_development_dependency 'database_cleaner'
27
+ spec.add_development_dependency 'database_cleaner', '~> 1.3.0'
27
28
  spec.add_development_dependency 'elasticsearch-extensions'
28
29
  spec.add_development_dependency 'rubysl', '~> 2.0' if RUBY_ENGINE == 'rbx'
29
30
 
@@ -0,0 +1,13 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "activerecord", "~> 3.2.0"
6
+ gem "activesupport", "~> 3.2.0"
7
+
8
+ group :test do
9
+ gem "guard"
10
+ gem "guard-rspec"
11
+ end
12
+
13
+ gemspec :path => "../"
@@ -0,0 +1,14 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "activerecord", "~> 3.2.0"
6
+ gem "activesupport", "~> 3.2.0"
7
+ gem "kaminari", :require => false
8
+
9
+ group :test do
10
+ gem "guard"
11
+ gem "guard-rspec"
12
+ end
13
+
14
+ gemspec :path => "../"
@@ -0,0 +1,14 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "activerecord", "~> 3.2.0"
6
+ gem "activesupport", "~> 3.2.0"
7
+ gem "will_paginate", :require => false
8
+
9
+ group :test do
10
+ gem "guard"
11
+ gem "guard-rspec"
12
+ end
13
+
14
+ gemspec :path => "../"
@@ -0,0 +1,13 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "activerecord", "~> 4.0.0"
6
+ gem "activesupport", "~> 4.0.0"
7
+
8
+ group :test do
9
+ gem "guard"
10
+ gem "guard-rspec"
11
+ end
12
+
13
+ gemspec :path => "../"
@@ -0,0 +1,14 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "activerecord", "~> 4.0.0"
6
+ gem "activesupport", "~> 4.0.0"
7
+ gem "kaminari", :require => false
8
+
9
+ group :test do
10
+ gem "guard"
11
+ gem "guard-rspec"
12
+ end
13
+
14
+ gemspec :path => "../"
@@ -0,0 +1,14 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "activerecord", "~> 4.0.0"
6
+ gem "activesupport", "~> 4.0.0"
7
+ gem "will_paginate", :require => false
8
+
9
+ group :test do
10
+ gem "guard"
11
+ gem "guard-rspec"
12
+ end
13
+
14
+ gemspec :path => "../"
@@ -0,0 +1,13 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "mongoid", "~> 4.0.0"
6
+ gem "activesupport", "~> 4.0.0"
7
+
8
+ group :test do
9
+ gem "guard"
10
+ gem "guard-rspec"
11
+ end
12
+
13
+ gemspec :path => "../"
@@ -0,0 +1,14 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "mongoid", "~> 4.0.0"
6
+ gem "activesupport", "~> 4.0.0"
7
+ gem "kaminari", :require => false
8
+
9
+ group :test do
10
+ gem "guard"
11
+ gem "guard-rspec"
12
+ end
13
+
14
+ gemspec :path => "../"
@@ -0,0 +1,14 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "mongoid", "~> 4.0.0"
6
+ gem "activesupport", "~> 4.0.0"
7
+ gem "will_paginate", :require => false
8
+
9
+ group :test do
10
+ gem "guard"
11
+ gem "guard-rspec"
12
+ end
13
+
14
+ gemspec :path => "../"
@@ -0,0 +1,13 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "activerecord", "~> 4.1.0"
6
+ gem "activesupport", "~> 4.1.0"
7
+
8
+ group :test do
9
+ gem "guard"
10
+ gem "guard-rspec"
11
+ end
12
+
13
+ gemspec :path => "../"
@@ -0,0 +1,14 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "activerecord", "~> 4.1.0"
6
+ gem "activesupport", "~> 4.1.0"
7
+ gem "kaminari", :require => false
8
+
9
+ group :test do
10
+ gem "guard"
11
+ gem "guard-rspec"
12
+ end
13
+
14
+ gemspec :path => "../"
@@ -0,0 +1,14 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "activerecord", "~> 4.1.0"
6
+ gem "activesupport", "~> 4.1.0"
7
+ gem "will_paginate", :require => false
8
+
9
+ group :test do
10
+ gem "guard"
11
+ gem "guard-rspec"
12
+ end
13
+
14
+ gemspec :path => "../"
@@ -0,0 +1,13 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "mongoid", "~> 4.0.0"
6
+ gem "activesupport", "~> 4.1.0"
7
+
8
+ group :test do
9
+ gem "guard"
10
+ gem "guard-rspec"
11
+ end
12
+
13
+ gemspec :path => "../"
@@ -0,0 +1,14 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "mongoid", "~> 4.0.0"
6
+ gem "activesupport", "~> 4.1.0"
7
+ gem "kaminari", :require => false
8
+
9
+ group :test do
10
+ gem "guard"
11
+ gem "guard-rspec"
12
+ end
13
+
14
+ gemspec :path => "../"
@@ -0,0 +1,14 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "mongoid", "~> 4.0.0"
6
+ gem "activesupport", "~> 4.1.0"
7
+ gem "will_paginate", :require => false
8
+
9
+ group :test do
10
+ gem "guard"
11
+ gem "guard-rspec"
12
+ end
13
+
14
+ gemspec :path => "../"
@@ -0,0 +1,13 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "activerecord", "~> 4.2.0"
6
+ gem "activesupport", "~> 4.2.0"
7
+
8
+ group :test do
9
+ gem "guard"
10
+ gem "guard-rspec"
11
+ end
12
+
13
+ gemspec :path => "../"
@@ -0,0 +1,14 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "activerecord", "~> 4.2.0"
6
+ gem "activesupport", "~> 4.2.0"
7
+ gem "kaminari", :require => false
8
+
9
+ group :test do
10
+ gem "guard"
11
+ gem "guard-rspec"
12
+ end
13
+
14
+ gemspec :path => "../"
@@ -0,0 +1,14 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "activerecord", "~> 4.2.0"
6
+ gem "activesupport", "~> 4.2.0"
7
+ gem "will_paginate", :require => false
8
+
9
+ group :test do
10
+ gem "guard"
11
+ gem "guard-rspec"
12
+ end
13
+
14
+ gemspec :path => "../"
@@ -0,0 +1,13 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "mongoid", "~> 4.0.0"
6
+ gem "activesupport", "~> 4.2.0"
7
+
8
+ group :test do
9
+ gem "guard"
10
+ gem "guard-rspec"
11
+ end
12
+
13
+ gemspec :path => "../"
@@ -0,0 +1,14 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "mongoid", "~> 4.0.0"
6
+ gem "activesupport", "~> 4.2.0"
7
+ gem "kaminari", :require => false
8
+
9
+ group :test do
10
+ gem "guard"
11
+ gem "guard-rspec"
12
+ end
13
+
14
+ gemspec :path => "../"
@@ -0,0 +1,14 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "mongoid", "~> 4.0.0"
6
+ gem "activesupport", "~> 4.2.0"
7
+ gem "will_paginate", :require => false
8
+
9
+ group :test do
10
+ gem "guard"
11
+ gem "guard-rspec"
12
+ end
13
+
14
+ gemspec :path => "../"
@@ -1,4 +1,5 @@
1
1
  require 'active_support'
2
+ require 'active_support/log_subscriber'
2
3
  require 'active_support/deprecation'
3
4
  require 'active_support/core_ext'
4
5
  require 'active_support/concern'
@@ -12,7 +13,10 @@ require 'elasticsearch'
12
13
  require 'chewy/version'
13
14
  require 'chewy/errors'
14
15
  require 'chewy/config'
16
+ require 'chewy/repository'
15
17
  require 'chewy/runtime'
18
+ require 'chewy/log_subscriber'
19
+ require 'chewy/strategy'
16
20
  require 'chewy/index'
17
21
  require 'chewy/type'
18
22
  require 'chewy/fields/base'
@@ -103,6 +107,12 @@ module Chewy
103
107
  type
104
108
  end
105
109
 
110
+ # Main elasticsearch-ruby client instance
111
+ #
112
+ def client
113
+ Thread.current[:chewy_client] ||= ::Elasticsearch::Client.new configuration
114
+ end
115
+
106
116
  # Sends wait_for_status request to ElasticSearch with status
107
117
  # defined in configuration.
108
118
  #
@@ -121,9 +131,64 @@ module Chewy
121
131
  end
122
132
  alias_method :delete_all, :massacre
123
133
 
134
+ # Strategies are designed to allow nesting, so it is possible
135
+ # to redefine it for nested contexts.
136
+ #
137
+ # Chewy.strategy(:atomic) do
138
+ # city1.do_update!
139
+ # Chewy.strategy(:urgent) do
140
+ # city2.do_update!
141
+ # city3.do_update!
142
+ # # there will be 2 update index requests for city2 and city3
143
+ # end
144
+ # city4..do_update!
145
+ # # city1 and city4 will be grouped in one index update request
146
+ # end
147
+ #
148
+ # It is possible to nest strategies without blocks:
149
+ #
150
+ # Chewy.strategy(:urgent)
151
+ # city1.do_update! # index updated
152
+ # Chewy.strategy(:bypass)
153
+ # city2.do_update! # update bypassed
154
+ # Chewy.strategy.pop
155
+ # city3.do_update! # index updated again
156
+ #
157
+ def strategy name = nil, &block
158
+ Thread.current[:chewy_strategy] ||= Chewy::Strategy.new
159
+ if name
160
+ if block
161
+ Thread.current[:chewy_strategy].wrap name, &block
162
+ else
163
+ Thread.current[:chewy_strategy].push name
164
+ end
165
+ else
166
+ Thread.current[:chewy_strategy]
167
+ end
168
+ end
169
+
170
+ def urgent_update= value
171
+ ActiveSupport::Deprecation.warn('`Chewy.urgent_update = value` is deprecated and will be removed soon, use `Chewy.strategy(:urgent)` block instead')
172
+ if value
173
+ strategy(:urgent)
174
+ else
175
+ strategy.pop
176
+ end
177
+ end
178
+
179
+ def atomic &block
180
+ ActiveSupport::Deprecation.warn('`Chewy.atomic` block is deprecated and will be removed soon, use `Chewy.strategy(:atomic)` block instead')
181
+ strategy(:atomic, &block)
182
+ end
183
+
124
184
  def config
125
185
  Chewy::Config.instance
126
186
  end
127
187
  delegate *Chewy::Config.delegated, to: :config
188
+
189
+ def repository
190
+ Chewy::Repository.instance
191
+ end
192
+ delegate *Chewy::Repository.delegated, to: :repository
128
193
  end
129
194
  end
@@ -2,20 +2,7 @@ module Chewy
2
2
  class Config
3
3
  include Singleton
4
4
 
5
- attr_reader :analyzers, :tokenizers, :filters, :char_filters
6
- attr_accessor :configuration,
7
- # Just sets up logger to current configuration
8
- #
9
- # Chewy.logger = Rails.logger
10
- #
11
- :logger,
12
-
13
- # Urgent update default value. False by default. Urgent
14
- # updates are useful for testing, so don't use it in the
15
- # application code. Prefer `Chewy.atomic` block for cumulative
16
- # index updates.
17
- #
18
- :urgent_update,
5
+ attr_accessor :settings, :transport_logger, :transport_tracer, :logger,
19
6
 
20
7
  # Default query compilation mode. `:must` by default.
21
8
  # See Chewy::Query#query_mode for details
@@ -30,68 +17,52 @@ module Chewy
30
17
  # Default post_filters compilation mode. `nil` by default.
31
18
  # See Chewy::Query#post_filter_mode for details
32
19
  #
33
- :post_filter_mode
20
+ :post_filter_mode,
34
21
 
35
- def self.delegated
36
- public_instance_methods - self.superclass.public_instance_methods - Singleton.public_instance_methods
37
- end
22
+ # The first trategy in stack. `:base` by default.
23
+ # If you neet to return to the previous chewy behavior -
24
+ # just set it to `:bypass`
25
+ #
26
+ :root_strategy,
38
27
 
39
- def self.repository name
40
- plural_name = name.to_s.pluralize
28
+ # The first trategy in stack. `:base` by default.
29
+ # If you neet to return to the previous chewy behavior -
30
+ # just set it to `:bypass`
31
+ #
32
+ :request_strategy,
41
33
 
42
- class_eval <<-METHOD, __FILE__, __LINE__ + 1
43
- def #{name}(name, options = nil)
44
- options ? #{plural_name}[name.to_sym] = options : #{plural_name}[name.to_sym]
45
- end
46
- METHOD
34
+ # Use after_commit callbacks for RDBMS instead of
35
+ # after_save and after_destroy. True by default. Useful
36
+ # in tests with transactional fixtures or transactional
37
+ # DatabaseCleaner strategy.
38
+ #
39
+ :use_after_commit_callbacks
40
+
41
+ def self.delegated
42
+ public_instance_methods - self.superclass.public_instance_methods - Singleton.public_instance_methods
47
43
  end
48
44
 
49
45
  def initialize
50
- @configuration = {}
51
- @urgent_update = false
46
+ @settings = {}
52
47
  @query_mode = :must
53
48
  @filter_mode = :and
54
- @analyzers = {}
55
- @tokenizers = {}
56
- @filters = {}
57
- @char_filters = {}
49
+ @root_strategy = :base
50
+ @request_strategy = :atomic
51
+ @use_after_commit_callbacks = true
58
52
  end
59
53
 
60
- # Analysers repository:
61
- #
62
- # Chewy.analyzer :my_analyzer2, {
63
- # type: custom,
64
- # tokenizer: 'my_tokenizer1',
65
- # filter : ['my_token_filter1', 'my_token_filter2']
66
- # char_filter : ['my_html']
67
- # }
68
- # Chewy.analyzer(:my_analyzer2) # => {type: 'custom', tokenizer: ...}
69
- #
70
- repository :analyzer
71
-
72
- # Tokenizers repository:
73
- #
74
- # Chewy.tokenizer :my_tokenizer1, {type: standard, max_token_length: 900}
75
- # Chewy.tokenizer(:my_tokenizer1) # => {type: standard, max_token_length: 900}
76
- #
77
- repository :tokenizer
78
-
79
- # Token filters repository:
80
- #
81
- # Chewy.filter :my_token_filter1, {type: stop, stopwords: [stop1, stop2, stop3, stop4]}
82
- # Chewy.filter(:my_token_filter1) # => {type: stop, stopwords: [stop1, stop2, stop3, stop4]}
83
- #
84
- repository :filter
54
+ def transport_logger= logger
55
+ Chewy.client.transport.logger = logger
56
+ @transport_logger = logger
57
+ end
85
58
 
86
- # Char filters repository:
87
- #
88
- # Chewy.char_filter :my_html, {type: html_strip, escaped_tags: [xxx, yyy], read_ahead: 1024}
89
- # Chewy.char_filter(:my_html) # => {type: html_strip, escaped_tags: [xxx, yyy], read_ahead: 1024}
90
- #
91
- repository :char_filter
59
+ def transport_tracer= tracer
60
+ Chewy.client.transport.tracer = tracer
61
+ @transport_tracer = tracer
62
+ end
92
63
 
93
64
  # Chewy core configurations. There is two ways to set it up:
94
- # use `Chewy.configuration=` method or, for Rails application,
65
+ # use `Chewy.settings=` method or, for Rails application,
95
66
  # create `config/chewy.yml` file. Btw, `config/chewy.yml` supports
96
67
  # ERB the same way as ActiveRecord's config.
97
68
  #
@@ -134,45 +105,25 @@ module Chewy
134
105
  # number_of_replicas: 0
135
106
  #
136
107
  def configuration
137
- options = @configuration.deep_symbolize_keys.merge(yaml_options)
138
- options.merge!(logger: logger) if logger
139
- options
140
- end
141
-
142
- def client
143
- Thread.current[:chewy_client] ||= ::Elasticsearch::Client.new configuration
144
- end
145
-
146
- def atomic?
147
- stash.any?
148
- end
149
-
150
- def atomic
151
- stash.push({})
152
- yield
153
- ensure
154
- stash.pop.each { |type, ids| type.import(ids) }
108
+ yaml_settings.merge(settings.deep_symbolize_keys).tap do |configuration|
109
+ configuration.merge(logger: transport_logger) if transport_logger
110
+ configuration.merge(tracer: transport_tracer) if transport_tracer
111
+ end
155
112
  end
156
113
 
157
- def stash *args
158
- if args.any?
159
- type, ids = *args
160
- raise ArgumentError.new('Only Chewy::Type accepted as the first argument') unless type < Chewy::Type
161
- stash.last[type] ||= []
162
- stash.last[type] |= ids
163
- else
164
- Thread.current[:chewy_cache] ||= []
165
- end
114
+ def configuration= options
115
+ ActiveSupport::Deprecation.warn("`Chewy.configuration = {foo: 'bar'}` method is deprecated and will be removed soon, use `Chewy.settings = {foo: 'bar'}` method instead")
116
+ self.settings = options
166
117
  end
167
118
 
168
119
  private
169
120
 
170
- def yaml_options
171
- @yaml_options ||= begin
121
+ def yaml_settings
122
+ @yaml_settings ||= begin
172
123
  if defined?(Rails)
173
124
  file = Rails.root.join(*%w(config chewy.yml))
174
125
 
175
- if File.exists?(file)
126
+ if File.exist?(file)
176
127
  yaml = ERB.new(File.read(file)).result
177
128
  hash = YAML.load(yaml)
178
129
  hash[Rails.env].try(:deep_symbolize_keys) if hash