chewy 7.1.0 → 7.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/ruby.yml +58 -0
- data/.rubocop.yml +13 -8
- data/.rubocop_todo.yml +110 -22
- data/CHANGELOG.md +53 -0
- data/Gemfile +0 -7
- data/Guardfile +3 -1
- data/README.md +282 -245
- data/chewy.gemspec +3 -5
- data/gemfiles/rails.5.2.activerecord.gemfile +8 -14
- data/gemfiles/rails.6.0.activerecord.gemfile +8 -14
- data/gemfiles/rails.6.1.activerecord.gemfile +8 -14
- data/lib/chewy.rb +21 -75
- data/lib/chewy/config.rb +40 -40
- data/lib/chewy/errors.rb +0 -12
- data/lib/chewy/fields/base.rb +11 -1
- data/lib/chewy/fields/root.rb +3 -4
- data/lib/chewy/index.rb +46 -87
- data/lib/chewy/index/actions.rb +51 -32
- data/lib/chewy/{type → index}/adapter/active_record.rb +12 -3
- data/lib/chewy/{type → index}/adapter/base.rb +2 -3
- data/lib/chewy/{type → index}/adapter/object.rb +27 -31
- data/lib/chewy/{type → index}/adapter/orm.rb +11 -14
- data/lib/chewy/{type → index}/crutch.rb +5 -5
- data/lib/chewy/{type → index}/import.rb +36 -27
- data/lib/chewy/{type → index}/import/bulk_builder.rb +15 -13
- data/lib/chewy/{type → index}/import/bulk_request.rb +6 -6
- data/lib/chewy/{type → index}/import/journal_builder.rb +10 -10
- data/lib/chewy/{type → index}/import/routine.rb +15 -14
- data/lib/chewy/{type → index}/mapping.rb +26 -31
- data/lib/chewy/{type → index}/observe.rb +9 -19
- data/lib/chewy/index/specification.rb +1 -0
- data/lib/chewy/{type → index}/syncer.rb +60 -57
- data/lib/chewy/{type → index}/witchcraft.rb +11 -7
- data/lib/chewy/{type → index}/wrapper.rb +2 -2
- data/lib/chewy/journal.rb +8 -8
- data/lib/chewy/minitest/helpers.rb +9 -13
- data/lib/chewy/minitest/search_index_receiver.rb +22 -26
- data/lib/chewy/railtie.rb +4 -2
- data/lib/chewy/rake_helper.rb +82 -107
- data/lib/chewy/rspec/update_index.rb +47 -43
- data/lib/chewy/search.rb +4 -17
- data/lib/chewy/search/loader.rb +18 -30
- data/lib/chewy/search/parameters.rb +4 -2
- data/lib/chewy/search/parameters/concerns/query_storage.rb +2 -2
- data/lib/chewy/search/parameters/source.rb +5 -1
- data/lib/chewy/search/query_proxy.rb +9 -2
- data/lib/chewy/search/request.rb +82 -86
- data/lib/chewy/search/response.rb +4 -4
- data/lib/chewy/search/scoping.rb +6 -7
- data/lib/chewy/search/scrolling.rb +11 -11
- data/lib/chewy/stash.rb +14 -22
- data/lib/chewy/strategy.rb +3 -19
- data/lib/chewy/strategy/sidekiq.rb +1 -0
- data/lib/chewy/version.rb +1 -1
- data/lib/generators/chewy/install_generator.rb +1 -1
- data/lib/tasks/chewy.rake +10 -22
- data/migration_guide.md +14 -0
- data/spec/chewy/config_spec.rb +14 -39
- data/spec/chewy/fields/base_spec.rb +412 -148
- data/spec/chewy/fields/root_spec.rb +16 -24
- data/spec/chewy/fields/time_fields_spec.rb +5 -5
- data/spec/chewy/index/actions_spec.rb +270 -24
- data/spec/chewy/{type → index}/adapter/active_record_spec.rb +68 -40
- data/spec/chewy/{type → index}/adapter/object_spec.rb +21 -6
- data/spec/chewy/{type → index}/import/bulk_builder_spec.rb +23 -31
- data/spec/chewy/{type → index}/import/bulk_request_spec.rb +5 -6
- data/spec/chewy/{type → index}/import/journal_builder_spec.rb +9 -15
- data/spec/chewy/{type → index}/import/routine_spec.rb +16 -16
- data/spec/chewy/{type → index}/import_spec.rb +102 -98
- data/spec/chewy/{type → index}/mapping_spec.rb +46 -54
- data/spec/chewy/index/observe_spec.rb +116 -0
- data/spec/chewy/index/settings_spec.rb +3 -1
- data/spec/chewy/index/specification_spec.rb +7 -17
- data/spec/chewy/{type → index}/syncer_spec.rb +14 -19
- data/spec/chewy/{type → index}/witchcraft_spec.rb +20 -22
- data/spec/chewy/index/wrapper_spec.rb +100 -0
- data/spec/chewy/index_spec.rb +59 -102
- data/spec/chewy/journal_spec.rb +9 -22
- data/spec/chewy/minitest/helpers_spec.rb +13 -15
- data/spec/chewy/minitest/search_index_receiver_spec.rb +22 -26
- data/spec/chewy/multi_search_spec.rb +4 -5
- data/spec/chewy/rake_helper_spec.rb +145 -55
- data/spec/chewy/rspec/update_index_spec.rb +74 -71
- data/spec/chewy/search/loader_spec.rb +19 -37
- data/spec/chewy/search/pagination/kaminari_examples.rb +3 -5
- data/spec/chewy/search/pagination/kaminari_spec.rb +1 -1
- data/spec/chewy/search/parameters/indices_spec.rb +2 -8
- data/spec/chewy/search/parameters/order_spec.rb +1 -1
- data/spec/chewy/search/parameters/query_storage_examples.rb +67 -21
- data/spec/chewy/search/parameters/search_after_spec.rb +4 -1
- data/spec/chewy/search/parameters/source_spec.rb +8 -2
- data/spec/chewy/search/parameters_spec.rb +12 -3
- data/spec/chewy/search/query_proxy_spec.rb +68 -17
- data/spec/chewy/search/request_spec.rb +222 -74
- data/spec/chewy/search/response_spec.rb +12 -12
- data/spec/chewy/search/scrolling_spec.rb +7 -9
- data/spec/chewy/search_spec.rb +32 -35
- data/spec/chewy/stash_spec.rb +9 -21
- data/spec/chewy/strategy/active_job_spec.rb +8 -8
- data/spec/chewy/strategy/atomic_spec.rb +9 -10
- data/spec/chewy/strategy/sidekiq_spec.rb +8 -8
- data/spec/chewy/strategy_spec.rb +19 -15
- data/spec/chewy_spec.rb +14 -100
- data/spec/spec_helper.rb +2 -21
- data/spec/support/active_record.rb +15 -5
- metadata +44 -103
- data/.circleci/config.yml +0 -214
- data/Appraisals +0 -81
- data/gemfiles/rails.5.2.mongoid.6.4.gemfile +0 -17
- data/gemfiles/sequel.4.45.gemfile +0 -11
- data/lib/chewy/search/pagination/will_paginate.rb +0 -43
- data/lib/chewy/strategy/resque.rb +0 -27
- data/lib/chewy/strategy/shoryuken.rb +0 -40
- data/lib/chewy/type.rb +0 -120
- data/lib/chewy/type/actions.rb +0 -43
- data/lib/chewy/type/adapter/mongoid.rb +0 -67
- data/lib/chewy/type/adapter/sequel.rb +0 -93
- data/lib/sequel/plugins/chewy_observe.rb +0 -63
- data/spec/chewy/search/pagination/will_paginate_examples.rb +0 -63
- data/spec/chewy/search/pagination/will_paginate_spec.rb +0 -23
- data/spec/chewy/strategy/resque_spec.rb +0 -46
- data/spec/chewy/strategy/shoryuken_spec.rb +0 -70
- data/spec/chewy/type/actions_spec.rb +0 -50
- data/spec/chewy/type/adapter/mongoid_spec.rb +0 -372
- data/spec/chewy/type/adapter/sequel_spec.rb +0 -472
- data/spec/chewy/type/observe_spec.rb +0 -137
- data/spec/chewy/type/wrapper_spec.rb +0 -100
- data/spec/chewy/type_spec.rb +0 -55
- data/spec/support/mongoid.rb +0 -93
- data/spec/support/sequel.rb +0 -80
data/chewy.gemspec
CHANGED
@@ -1,8 +1,8 @@
|
|
1
|
-
lib = File.expand_path('
|
1
|
+
lib = File.expand_path('lib', __dir__)
|
2
2
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
3
|
require 'chewy/version'
|
4
4
|
|
5
|
-
Gem::Specification.new do |spec| # rubocop:disable BlockLength
|
5
|
+
Gem::Specification.new do |spec| # rubocop:disable Metrics/BlockLength
|
6
6
|
spec.name = 'chewy'
|
7
7
|
spec.version = Chewy::VERSION
|
8
8
|
spec.authors = ['Toptal, LLC', 'pyromaniac']
|
@@ -17,15 +17,13 @@ Gem::Specification.new do |spec| # rubocop:disable BlockLength
|
|
17
17
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
18
18
|
spec.require_paths = ['lib']
|
19
19
|
|
20
|
-
spec.add_development_dependency 'appraisal'
|
21
20
|
spec.add_development_dependency 'database_cleaner'
|
22
21
|
spec.add_development_dependency 'elasticsearch-extensions'
|
23
22
|
spec.add_development_dependency 'rake'
|
24
|
-
spec.add_development_dependency 'resque_spec'
|
25
23
|
spec.add_development_dependency 'rspec', '>= 3.7.0'
|
26
24
|
spec.add_development_dependency 'rspec-collection_matchers'
|
27
25
|
spec.add_development_dependency 'rspec-its'
|
28
|
-
spec.add_development_dependency 'rubocop', '
|
26
|
+
spec.add_development_dependency 'rubocop', '1.11'
|
29
27
|
spec.add_development_dependency 'sqlite3'
|
30
28
|
spec.add_development_dependency 'timecop'
|
31
29
|
|
@@ -1,17 +1,11 @@
|
|
1
|
-
|
1
|
+
source 'https://rubygems.org'
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
gem
|
6
|
-
gem
|
7
|
-
gem
|
8
|
-
gem "resque", require: false
|
9
|
-
gem "shoryuken", require: false
|
10
|
-
gem "aws-sdk-sqs", require: false
|
11
|
-
gem "sidekiq", require: false
|
12
|
-
gem "kaminari-core", "~> 1.1.0", require: false
|
13
|
-
gem "will_paginate", require: false
|
14
|
-
gem "parallel", require: false
|
3
|
+
gem 'activejob', '~> 5.2.0'
|
4
|
+
gem 'activerecord', '~> 5.2.0'
|
5
|
+
gem 'activesupport', '~> 5.2.0'
|
6
|
+
gem 'kaminari-core', '~> 1.1.0', require: false
|
7
|
+
gem 'parallel', require: false
|
15
8
|
gem 'rspec_junit_formatter', '~> 0.4.1'
|
9
|
+
gem 'sidekiq', require: false
|
16
10
|
|
17
|
-
gemspec path:
|
11
|
+
gemspec path: '../'
|
@@ -1,17 +1,11 @@
|
|
1
|
-
|
1
|
+
source 'https://rubygems.org'
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
gem
|
6
|
-
gem
|
7
|
-
gem
|
8
|
-
gem "resque", require: false
|
9
|
-
gem "shoryuken", require: false
|
10
|
-
gem "aws-sdk-sqs", require: false
|
11
|
-
gem "sidekiq", require: false
|
12
|
-
gem "kaminari-core", "~> 1.1.0", require: false
|
13
|
-
gem "will_paginate", require: false
|
14
|
-
gem "parallel", require: false
|
3
|
+
gem 'activejob', '~> 6.0.0'
|
4
|
+
gem 'activerecord', '~> 6.0.0'
|
5
|
+
gem 'activesupport', '~> 6.0.0'
|
6
|
+
gem 'kaminari-core', '~> 1.1.0', require: false
|
7
|
+
gem 'parallel', require: false
|
15
8
|
gem 'rspec_junit_formatter', '~> 0.4.1'
|
9
|
+
gem 'sidekiq', require: false
|
16
10
|
|
17
|
-
gemspec path:
|
11
|
+
gemspec path: '../'
|
@@ -1,19 +1,13 @@
|
|
1
|
-
|
1
|
+
source 'https://rubygems.org'
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
gem
|
6
|
-
gem
|
7
|
-
gem
|
8
|
-
gem "resque", require: false
|
9
|
-
gem "shoryuken", require: false
|
10
|
-
gem "aws-sdk-sqs", require: false
|
11
|
-
gem "sidekiq", require: false
|
12
|
-
gem "kaminari-core", "~> 1.1.0", require: false
|
13
|
-
gem "will_paginate", require: false
|
14
|
-
gem "parallel", require: false
|
3
|
+
gem 'activejob', '~> 6.1.0'
|
4
|
+
gem 'activerecord', '~> 6.1.0'
|
5
|
+
gem 'activesupport', '~> 6.1.0'
|
6
|
+
gem 'kaminari-core', '~> 1.1.0', require: false
|
7
|
+
gem 'parallel', require: false
|
15
8
|
gem 'rspec_junit_formatter', '~> 0.4.1'
|
9
|
+
gem 'sidekiq', require: false
|
16
10
|
|
17
11
|
gem 'rexml' if RUBY_VERSION >= '3.0.0'
|
18
12
|
|
19
|
-
gemspec path:
|
13
|
+
gemspec path: '../'
|
data/lib/chewy.rb
CHANGED
@@ -29,20 +29,12 @@ end
|
|
29
29
|
|
30
30
|
try_require 'kaminari'
|
31
31
|
try_require 'kaminari/core'
|
32
|
-
try_require 'will_paginate'
|
33
|
-
try_require 'will_paginate/collection'
|
34
32
|
try_require 'parallel'
|
35
33
|
|
36
34
|
ActiveSupport.on_load(:active_record) do
|
37
|
-
try_require 'will_paginate/active_record'
|
38
35
|
try_require 'kaminari/activerecord'
|
39
36
|
end
|
40
37
|
|
41
|
-
ActiveSupport.on_load(:mongoid) do
|
42
|
-
try_require 'will_paginate/mongoid'
|
43
|
-
try_require 'kaminari/mongoid'
|
44
|
-
end
|
45
|
-
|
46
38
|
require 'chewy/version'
|
47
39
|
require 'chewy/errors'
|
48
40
|
require 'chewy/config'
|
@@ -52,94 +44,43 @@ require 'chewy/runtime'
|
|
52
44
|
require 'chewy/log_subscriber'
|
53
45
|
require 'chewy/strategy'
|
54
46
|
require 'chewy/index'
|
55
|
-
require 'chewy/type'
|
56
47
|
require 'chewy/fields/base'
|
57
48
|
require 'chewy/fields/root'
|
58
49
|
require 'chewy/journal'
|
59
50
|
require 'chewy/railtie' if defined?(::Rails::Railtie)
|
60
51
|
|
61
52
|
ActiveSupport.on_load(:active_record) do
|
62
|
-
extend Chewy::
|
63
|
-
end
|
64
|
-
|
65
|
-
ActiveSupport.on_load(:mongoid) do
|
66
|
-
module Mongoid
|
67
|
-
module Document
|
68
|
-
module ClassMethods
|
69
|
-
include Chewy::Type::Observe::MongoidMethods
|
70
|
-
end
|
71
|
-
end
|
72
|
-
end
|
53
|
+
extend Chewy::Index::Observe::ActiveRecordMethods
|
73
54
|
end
|
74
55
|
|
75
56
|
module Chewy
|
76
57
|
@adapters = [
|
77
|
-
Chewy::
|
78
|
-
Chewy::
|
79
|
-
Chewy::Type::Adapter::Sequel,
|
80
|
-
Chewy::Type::Adapter::Object
|
58
|
+
Chewy::Index::Adapter::ActiveRecord,
|
59
|
+
Chewy::Index::Adapter::Object
|
81
60
|
]
|
82
61
|
|
83
62
|
class << self
|
84
63
|
attr_accessor :adapters
|
85
64
|
|
86
|
-
# Derives
|
87
|
-
#
|
88
|
-
# @example
|
89
|
-
# Chewy.derive_types(UsersIndex::User) # => UsersIndex::User
|
90
|
-
# Chewy.derive_types('namespace/users') # => Namespace::UsersIndex::User
|
91
|
-
# Chewy.derive_types('places') # => raises Chewy::UnderivableType
|
92
|
-
# Chewy.derive_types('places#city') # => PlacesIndex::City
|
93
|
-
#
|
94
|
-
# @param name [String, Chewy::Type] string type identifier
|
95
|
-
# @raise [Chewy::UnderivableType] in cases when it is impossble to find index or type or more than one type found
|
96
|
-
# @return [Chewy::Type] an array of derived types
|
97
|
-
def derive_type(name)
|
98
|
-
return name if name.is_a?(Class) && name < Chewy::Type
|
99
|
-
|
100
|
-
types = derive_types(name)
|
101
|
-
raise Chewy::UnderivableType, "Index `#{types.first.index}` has more than one type, please specify type via `#{types.first.index.derivable_name}#type_name`" unless types.one?
|
102
|
-
types.first
|
103
|
-
end
|
104
|
-
|
105
|
-
# Derives all the types for the passed string identifier if possible.
|
65
|
+
# Derives an index for the passed string identifier if possible.
|
106
66
|
#
|
107
67
|
# @example
|
108
|
-
# Chewy.
|
109
|
-
# Chewy.
|
110
|
-
# Chewy.
|
68
|
+
# Chewy.derive_name(UsersIndex) # => UsersIndex
|
69
|
+
# Chewy.derive_name('namespace/users') # => Namespace::UsersIndex
|
70
|
+
# Chewy.derive_name('missing') # => raises Chewy::UndefinedIndex
|
111
71
|
#
|
112
|
-
# @param
|
113
|
-
# @raise [Chewy::
|
114
|
-
# @return [
|
115
|
-
def
|
116
|
-
return
|
72
|
+
# @param index_name [String, Chewy::Index] index identifier or class
|
73
|
+
# @raise [Chewy::UndefinedIndex] in cases when it is impossible to find index
|
74
|
+
# @return [Chewy::Index]
|
75
|
+
def derive_name(index_name)
|
76
|
+
return index_name if index_name.is_a?(Class) && index_name < Chewy::Index
|
117
77
|
|
118
|
-
index_name, type_name = from.split('#', 2)
|
119
78
|
class_name = "#{index_name.camelize.gsub(/Index\z/, '')}Index"
|
120
79
|
index = class_name.safe_constantize
|
121
|
-
raise Chewy::UnderivableType, "Can not find index named `#{class_name}`" unless index && index < Chewy::Index
|
122
|
-
if type_name.present?
|
123
|
-
type = index.type_hash[type_name] or raise Chewy::UnderivableType, "Index `#{class_name}` doesn`t have type named `#{type_name}`"
|
124
|
-
[type]
|
125
|
-
else
|
126
|
-
index.types
|
127
|
-
end
|
128
|
-
end
|
129
80
|
|
130
|
-
|
131
|
-
#
|
132
|
-
def create_type(index, target, options = {}, &block)
|
133
|
-
type = Class.new(Chewy::Type)
|
134
|
-
|
135
|
-
adapter = adapters.find { |klass| klass.accepts?(target) }.new(target, **options)
|
136
|
-
|
137
|
-
index.const_set(adapter.name, type)
|
138
|
-
type.send(:define_singleton_method, :index) { index }
|
139
|
-
type.send(:define_singleton_method, :adapter) { adapter }
|
81
|
+
return index if index && index < Chewy::Index
|
140
82
|
|
141
|
-
|
142
|
-
type
|
83
|
+
raise Chewy::UndefinedIndex, "Can not find index named `#{class_name}`"
|
143
84
|
end
|
144
85
|
|
145
86
|
# Main elasticsearch-ruby client instance
|
@@ -159,7 +100,9 @@ module Chewy
|
|
159
100
|
# Does nothing in case of config `wait_for_status` is undefined.
|
160
101
|
#
|
161
102
|
def wait_for_status
|
162
|
-
|
103
|
+
if Chewy.configuration[:wait_for_status].present?
|
104
|
+
client.cluster.health wait_for_status: Chewy.configuration[:wait_for_status]
|
105
|
+
end
|
163
106
|
end
|
164
107
|
|
165
108
|
# Deletes all corresponding indexes with current prefix from ElasticSearch.
|
@@ -227,7 +170,10 @@ module Chewy
|
|
227
170
|
|
228
171
|
def eager_load!
|
229
172
|
return unless defined?(Chewy::Railtie)
|
230
|
-
|
173
|
+
|
174
|
+
dirs = Chewy::Railtie.all_engines.map do |engine|
|
175
|
+
engine.paths[Chewy.configuration[:indices_path]]
|
176
|
+
end.compact.map(&:existent).flatten.uniq
|
231
177
|
|
232
178
|
dirs.each do |dir|
|
233
179
|
Dir.glob(File.join(dir, '**/*.rb')).each do |file|
|
data/lib/chewy/config.rb
CHANGED
@@ -3,43 +3,46 @@ module Chewy
|
|
3
3
|
include Singleton
|
4
4
|
|
5
5
|
attr_accessor :settings, :logger,
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
6
|
+
# The first strategy in stack. `:base` by default.
|
7
|
+
# If you need to return to the previous chewy behavior -
|
8
|
+
# just set it to `:bypass`
|
9
|
+
#
|
10
|
+
:root_strategy,
|
11
|
+
# Default request strategy middleware, used in e.g
|
12
|
+
# Rails controllers. See Chewy::Railtie::RequestStrategy
|
13
|
+
# for more info.
|
14
|
+
#
|
15
|
+
:request_strategy,
|
16
|
+
# Rails console strategy, `:urgent` by default.
|
17
|
+
#
|
18
|
+
:console_strategy,
|
19
|
+
# Use after_commit callbacks for RDBMS instead of
|
20
|
+
# after_save and after_destroy. True by default. Useful
|
21
|
+
# in tests with transactional fixtures or transactional
|
22
|
+
# DatabaseCleaner strategy.
|
23
|
+
#
|
24
|
+
:use_after_commit_callbacks,
|
25
|
+
# Where Chewy expects to find index definitions
|
26
|
+
# within a Rails app folder.
|
27
|
+
:indices_path,
|
28
|
+
# Set index refresh_interval setting to -1 before reset and put the original value after.
|
29
|
+
# If setting not present, put back to default 1s
|
30
|
+
# https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-update-settings.html
|
31
|
+
:reset_disable_refresh_interval,
|
32
|
+
# Set number_of_replicas to 0 before reset and put the original value after
|
33
|
+
# https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-update-settings.html
|
34
|
+
:reset_no_replicas,
|
35
|
+
# Refresh or not when import async (sidekiq, activejob)
|
36
|
+
:disable_refresh_async,
|
37
|
+
# Default options for root of Chewy type. Allows to set default options
|
38
|
+
# for type mappings like `_all`.
|
39
|
+
:default_root_options,
|
40
|
+
# Default field type for any field in any Chewy type. Defaults to 'text'.
|
41
|
+
:default_field_type
|
39
42
|
|
40
43
|
attr_reader :transport_logger, :transport_tracer,
|
41
|
-
|
42
|
-
|
44
|
+
# Chewy search request DSL base class, used by every index.
|
45
|
+
:search_class
|
43
46
|
|
44
47
|
def self.delegated
|
45
48
|
public_instance_methods - superclass.public_instance_methods - Singleton.public_instance_methods
|
@@ -49,6 +52,7 @@ module Chewy
|
|
49
52
|
@settings = {}
|
50
53
|
@root_strategy = :base
|
51
54
|
@request_strategy = :atomic
|
55
|
+
@console_strategy = :urgent
|
52
56
|
@use_after_commit_callbacks = true
|
53
57
|
@reset_disable_refresh_interval = false
|
54
58
|
@reset_no_replicas = false
|
@@ -138,11 +142,7 @@ module Chewy
|
|
138
142
|
|
139
143
|
def build_search_class(base)
|
140
144
|
Class.new(base).tap do |search_class|
|
141
|
-
if defined?(::Kaminari)
|
142
|
-
search_class.send :include, Chewy::Search::Pagination::Kaminari
|
143
|
-
elsif defined?(::WillPaginate)
|
144
|
-
search_class.send :include, Chewy::Search::Pagination::WillPaginate
|
145
|
-
end
|
145
|
+
search_class.send :include, Chewy::Search::Pagination::Kaminari if defined?(::Kaminari)
|
146
146
|
end
|
147
147
|
end
|
148
148
|
end
|
data/lib/chewy/errors.rb
CHANGED
@@ -5,12 +5,6 @@ module Chewy
|
|
5
5
|
class UndefinedIndex < Error
|
6
6
|
end
|
7
7
|
|
8
|
-
class UndefinedType < Error
|
9
|
-
end
|
10
|
-
|
11
|
-
class UnderivableType < Error
|
12
|
-
end
|
13
|
-
|
14
8
|
class UndefinedUpdateStrategy < Error
|
15
9
|
def initialize(_type)
|
16
10
|
super <<-MESSAGE
|
@@ -36,10 +30,4 @@ module Chewy
|
|
36
30
|
super message
|
37
31
|
end
|
38
32
|
end
|
39
|
-
|
40
|
-
class RemovedFeature < Error
|
41
|
-
end
|
42
|
-
|
43
|
-
class PluginMissing < Error
|
44
|
-
end
|
45
33
|
end
|
data/lib/chewy/fields/base.rb
CHANGED
@@ -40,6 +40,8 @@ module Chewy
|
|
40
40
|
def compose(*objects)
|
41
41
|
result = evaluate(objects)
|
42
42
|
|
43
|
+
return {} if result.blank? && ignore_blank?
|
44
|
+
|
43
45
|
if children.present? && !multi_field?
|
44
46
|
result = if result.respond_to?(:to_ary)
|
45
47
|
result.to_ary.map { |item| compose_children(item, *objects) }
|
@@ -53,13 +55,21 @@ module Chewy
|
|
53
55
|
|
54
56
|
private
|
55
57
|
|
58
|
+
def geo_point?
|
59
|
+
@options[:type].to_s == 'geo_point'
|
60
|
+
end
|
61
|
+
|
62
|
+
def ignore_blank?
|
63
|
+
@options.fetch(:ignore_blank) { geo_point? }
|
64
|
+
end
|
65
|
+
|
56
66
|
def evaluate(objects)
|
57
67
|
object = objects.first
|
58
68
|
|
59
69
|
if value.is_a?(Proc)
|
60
70
|
if value.arity.zero?
|
61
71
|
object.instance_exec(&value)
|
62
|
-
elsif value.arity
|
72
|
+
elsif value.arity.negative?
|
63
73
|
value.call(*object)
|
64
74
|
else
|
65
75
|
value.call(*objects.first(value.arity))
|
data/lib/chewy/fields/root.rb
CHANGED
@@ -1,10 +1,7 @@
|
|
1
1
|
module Chewy
|
2
2
|
module Fields
|
3
3
|
class Root < Chewy::Fields::Base
|
4
|
-
attr_reader :dynamic_templates
|
5
|
-
attr_reader :id
|
6
|
-
attr_reader :parent
|
7
|
-
attr_reader :parent_id
|
4
|
+
attr_reader :dynamic_templates, :id, :parent, :parent_id
|
8
5
|
|
9
6
|
def initialize(name, **options)
|
10
7
|
super(name, **options)
|
@@ -55,11 +52,13 @@ module Chewy
|
|
55
52
|
|
56
53
|
def compose_parent(object)
|
57
54
|
return unless parent_id
|
55
|
+
|
58
56
|
parent_id.arity.zero? ? object.instance_exec(&parent_id) : parent_id.call(object)
|
59
57
|
end
|
60
58
|
|
61
59
|
def compose_id(object)
|
62
60
|
return unless id
|
61
|
+
|
63
62
|
id.arity.zero? ? object.instance_exec(&id) : id.call(object)
|
64
63
|
end
|
65
64
|
|