chewy 0.8.4 → 0.9.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +34 -0
- data/.rubocop_todo.yml +44 -0
- data/.travis.yml +20 -60
- data/Appraisals +15 -40
- data/CHANGELOG.md +42 -0
- data/Gemfile +1 -0
- data/Guardfile +5 -5
- data/README.md +155 -6
- data/Rakefile +11 -1
- data/chewy.gemspec +5 -7
- data/gemfiles/rails.3.2.activerecord.gemfile +1 -0
- data/gemfiles/rails.3.2.activerecord.kaminari.gemfile +1 -0
- data/gemfiles/rails.3.2.activerecord.will_paginate.gemfile +1 -0
- data/gemfiles/rails.4.2.activerecord.gemfile +1 -0
- data/gemfiles/rails.4.2.activerecord.kaminari.gemfile +1 -0
- data/gemfiles/rails.4.2.activerecord.will_paginate.gemfile +1 -0
- data/gemfiles/{rails.4.2.mongoid.4.0.0.gemfile → rails.4.2.mongoid.4.0.gemfile} +2 -1
- data/gemfiles/{rails.4.2.mongoid.4.0.0.kaminari.gemfile → rails.4.2.mongoid.4.0.kaminari.gemfile} +2 -1
- data/gemfiles/{rails.4.2.mongoid.4.0.0.will_paginate.gemfile → rails.4.2.mongoid.4.0.will_paginate.gemfile} +2 -1
- data/gemfiles/{rails.4.2.mongoid.5.1.0.gemfile → rails.4.2.mongoid.5.1.gemfile} +2 -1
- data/gemfiles/{rails.4.2.mongoid.5.1.0.kaminari.gemfile → rails.4.2.mongoid.5.1.kaminari.gemfile} +2 -1
- data/gemfiles/{rails.4.2.mongoid.5.1.0.will_paginate.gemfile → rails.4.2.mongoid.5.1.will_paginate.gemfile} +2 -1
- data/gemfiles/{rails.4.0.activerecord.gemfile → rails.5.0.activerecord.gemfile} +4 -2
- data/gemfiles/{rails.4.0.mongoid.4.0.0.kaminari.gemfile → rails.5.0.activerecord.kaminari.gemfile} +4 -2
- data/gemfiles/{rails.4.0.mongoid.4.0.0.will_paginate.gemfile → rails.5.0.activerecord.will_paginate.gemfile} +4 -2
- data/gemfiles/{sequel.4.31.gemfile → sequel.4.38.gemfile} +3 -2
- data/lib/chewy.rb +24 -16
- data/lib/chewy/backports/deep_dup.rb +1 -1
- data/lib/chewy/backports/duplicable.rb +1 -0
- data/lib/chewy/config.rb +13 -7
- data/lib/chewy/errors.rb +4 -4
- data/lib/chewy/fields/base.rb +19 -14
- data/lib/chewy/fields/root.rb +11 -9
- data/lib/chewy/index.rb +38 -25
- data/lib/chewy/index/actions.rb +17 -17
- data/lib/chewy/index/settings.rb +3 -4
- data/lib/chewy/journal.rb +107 -0
- data/lib/chewy/journal/apply.rb +31 -0
- data/lib/chewy/journal/clean.rb +24 -0
- data/lib/chewy/journal/entry.rb +83 -0
- data/lib/chewy/journal/query.rb +87 -0
- data/lib/chewy/log_subscriber.rb +8 -8
- data/lib/chewy/minitest.rb +1 -0
- data/lib/chewy/minitest/helpers.rb +77 -0
- data/lib/chewy/minitest/search_index_receiver.rb +80 -0
- data/lib/chewy/query.rb +116 -60
- data/lib/chewy/query/compose.rb +5 -6
- data/lib/chewy/query/criteria.rb +26 -16
- data/lib/chewy/query/filters.rb +9 -9
- data/lib/chewy/query/loading.rb +2 -2
- data/lib/chewy/query/nodes/and.rb +3 -3
- data/lib/chewy/query/nodes/base.rb +1 -1
- data/lib/chewy/query/nodes/bool.rb +6 -4
- data/lib/chewy/query/nodes/equal.rb +6 -6
- data/lib/chewy/query/nodes/exists.rb +2 -2
- data/lib/chewy/query/nodes/expr.rb +2 -2
- data/lib/chewy/query/nodes/field.rb +35 -31
- data/lib/chewy/query/nodes/has_child.rb +1 -0
- data/lib/chewy/query/nodes/has_parent.rb +1 -0
- data/lib/chewy/query/nodes/has_relation.rb +11 -13
- data/lib/chewy/query/nodes/match_all.rb +1 -1
- data/lib/chewy/query/nodes/missing.rb +2 -2
- data/lib/chewy/query/nodes/not.rb +3 -3
- data/lib/chewy/query/nodes/or.rb +3 -3
- data/lib/chewy/query/nodes/prefix.rb +4 -3
- data/lib/chewy/query/nodes/query.rb +3 -3
- data/lib/chewy/query/nodes/range.rb +11 -11
- data/lib/chewy/query/nodes/raw.rb +1 -1
- data/lib/chewy/query/nodes/regexp.rb +15 -11
- data/lib/chewy/query/nodes/script.rb +6 -6
- data/lib/chewy/query/pagination/will_paginate.rb +2 -2
- data/lib/chewy/railtie.rb +3 -3
- data/lib/chewy/rake_helper.rb +51 -30
- data/lib/chewy/repository.rb +2 -2
- data/lib/chewy/rspec.rb +1 -1
- data/lib/chewy/rspec/update_index.rb +46 -47
- data/lib/chewy/runtime/version.rb +4 -4
- data/lib/chewy/search.rb +7 -5
- data/lib/chewy/strategy.rb +10 -8
- data/lib/chewy/strategy/atomic.rb +2 -2
- data/lib/chewy/strategy/base.rb +4 -4
- data/lib/chewy/strategy/bypass.rb +1 -2
- data/lib/chewy/strategy/sidekiq.rb +2 -0
- data/lib/chewy/strategy/urgent.rb +1 -1
- data/lib/chewy/type.rb +51 -45
- data/lib/chewy/type/adapter/active_record.rb +23 -12
- data/lib/chewy/type/adapter/base.rb +4 -4
- data/lib/chewy/type/adapter/mongoid.rb +6 -6
- data/lib/chewy/type/adapter/object.rb +15 -12
- data/lib/chewy/type/adapter/orm.rb +24 -15
- data/lib/chewy/type/adapter/sequel.rb +11 -7
- data/lib/chewy/type/crutch.rb +4 -3
- data/lib/chewy/type/import.rb +51 -32
- data/lib/chewy/type/mapping.rb +17 -17
- data/lib/chewy/type/observe.rb +9 -7
- data/lib/chewy/type/witchcraft.rb +62 -23
- data/lib/chewy/type/wrapper.rb +20 -14
- data/lib/chewy/version.rb +1 -1
- data/lib/generators/chewy/install_generator.rb +3 -3
- data/lib/tasks/chewy.rake +28 -23
- data/spec/chewy/config_spec.rb +33 -12
- data/spec/chewy/fields/base_spec.rb +143 -154
- data/spec/chewy/fields/root_spec.rb +22 -20
- data/spec/chewy/fields/time_fields_spec.rb +11 -9
- data/spec/chewy/index/actions_spec.rb +27 -4
- data/spec/chewy/index/aliases_spec.rb +2 -2
- data/spec/chewy/index/settings_spec.rb +72 -50
- data/spec/chewy/index_spec.rb +95 -43
- data/spec/chewy/journal/apply_spec.rb +120 -0
- data/spec/chewy/journal/entry_spec.rb +237 -0
- data/spec/chewy/journal_spec.rb +173 -0
- data/spec/chewy/minitest/helpers_spec.rb +90 -0
- data/spec/chewy/minitest/search_index_receiver_spec.rb +120 -0
- data/spec/chewy/query/criteria_spec.rb +504 -237
- data/spec/chewy/query/filters_spec.rb +94 -66
- data/spec/chewy/query/loading_spec.rb +76 -40
- data/spec/chewy/query/nodes/and_spec.rb +3 -7
- data/spec/chewy/query/nodes/bool_spec.rb +5 -13
- data/spec/chewy/query/nodes/equal_spec.rb +20 -20
- data/spec/chewy/query/nodes/exists_spec.rb +7 -7
- data/spec/chewy/query/nodes/has_child_spec.rb +42 -23
- data/spec/chewy/query/nodes/has_parent_spec.rb +42 -23
- data/spec/chewy/query/nodes/match_all_spec.rb +2 -2
- data/spec/chewy/query/nodes/missing_spec.rb +6 -5
- data/spec/chewy/query/nodes/not_spec.rb +3 -7
- data/spec/chewy/query/nodes/or_spec.rb +3 -7
- data/spec/chewy/query/nodes/prefix_spec.rb +6 -6
- data/spec/chewy/query/nodes/query_spec.rb +3 -3
- data/spec/chewy/query/nodes/range_spec.rb +19 -19
- data/spec/chewy/query/nodes/raw_spec.rb +2 -2
- data/spec/chewy/query/nodes/regexp_spec.rb +31 -19
- data/spec/chewy/query/nodes/script_spec.rb +5 -5
- data/spec/chewy/query/pagination/kaminari_spec.rb +2 -2
- data/spec/chewy/query/pagination/will_paginage_spec.rb +6 -7
- data/spec/chewy/query/pagination_spec.rb +2 -3
- data/spec/chewy/query_spec.rb +208 -145
- data/spec/chewy/repository_spec.rb +8 -8
- data/spec/chewy/rspec/update_index_spec.rb +180 -111
- data/spec/chewy/search_spec.rb +8 -8
- data/spec/chewy/strategy/active_job_spec.rb +2 -2
- data/spec/chewy/strategy/atomic_spec.rb +4 -1
- data/spec/chewy/strategy/resque_spec.rb +2 -2
- data/spec/chewy/strategy/sidekiq_spec.rb +2 -2
- data/spec/chewy/type/actions_spec.rb +1 -1
- data/spec/chewy/type/adapter/active_record_spec.rb +255 -149
- data/spec/chewy/type/adapter/mongoid_spec.rb +169 -108
- data/spec/chewy/type/adapter/object_spec.rb +56 -40
- data/spec/chewy/type/adapter/sequel_spec.rb +248 -163
- data/spec/chewy/type/import_spec.rb +78 -47
- data/spec/chewy/type/mapping_spec.rb +6 -6
- data/spec/chewy/type/observe_spec.rb +20 -14
- data/spec/chewy/type/witchcraft_spec.rb +89 -43
- data/spec/chewy/type_spec.rb +4 -3
- data/spec/chewy_spec.rb +10 -8
- data/spec/spec_helper.rb +3 -0
- data/spec/support/active_record.rb +1 -1
- data/spec/support/class_helpers.rb +10 -11
- data/spec/support/mongoid.rb +2 -2
- data/spec/support/sequel.rb +1 -1
- metadata +65 -35
- data/gemfiles/rails.4.0.activerecord.kaminari.gemfile +0 -14
- data/gemfiles/rails.4.0.activerecord.will_paginate.gemfile +0 -14
- data/gemfiles/rails.4.0.mongoid.4.0.0.gemfile +0 -15
- data/gemfiles/rails.4.0.mongoid.5.1.0.gemfile +0 -15
- data/gemfiles/rails.4.0.mongoid.5.1.0.kaminari.gemfile +0 -14
- data/gemfiles/rails.4.0.mongoid.5.1.0.will_paginate.gemfile +0 -14
- data/gemfiles/rails.4.1.activerecord.gemfile +0 -15
- data/gemfiles/rails.4.1.activerecord.kaminari.gemfile +0 -14
- data/gemfiles/rails.4.1.activerecord.will_paginate.gemfile +0 -14
- data/gemfiles/rails.4.1.mongoid.4.0.0.gemfile +0 -15
- data/gemfiles/rails.4.1.mongoid.4.0.0.kaminari.gemfile +0 -14
- data/gemfiles/rails.4.1.mongoid.4.0.0.will_paginate.gemfile +0 -14
- data/gemfiles/rails.4.1.mongoid.5.1.0.gemfile +0 -15
- data/gemfiles/rails.4.1.mongoid.5.1.0.kaminari.gemfile +0 -14
- data/gemfiles/rails.4.1.mongoid.5.1.0.will_paginate.gemfile +0 -14
- data/gemfiles/rails.5.0.0.beta3.activerecord.gemfile +0 -16
- data/gemfiles/rails.5.0.0.beta3.activerecord.kaminari.gemfile +0 -16
- data/gemfiles/rails.5.0.0.beta3.activerecord.will_paginate.gemfile +0 -15
data/Rakefile
CHANGED
@@ -4,4 +4,14 @@ require 'elasticsearch/extensions/test/cluster/tasks'
|
|
4
4
|
|
5
5
|
RSpec::Core::RakeTask.new(:spec)
|
6
6
|
|
7
|
-
task :
|
7
|
+
task default: :spec
|
8
|
+
|
9
|
+
namespace :es do
|
10
|
+
task :start do
|
11
|
+
Rake.application['elasticsearch:start'].invoke
|
12
|
+
end
|
13
|
+
|
14
|
+
task :stop do
|
15
|
+
Rake.application['elasticsearch:stop'].invoke
|
16
|
+
end
|
17
|
+
end
|
data/chewy.gemspec
CHANGED
@@ -3,7 +3,7 @@ lib = File.expand_path('../lib', __FILE__)
|
|
3
3
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
4
|
require 'chewy/version'
|
5
5
|
|
6
|
-
Gem::Specification.new do |spec|
|
6
|
+
Gem::Specification.new do |spec| # rubocop:disable BlockLength
|
7
7
|
spec.name = 'chewy'
|
8
8
|
spec.version = Chewy::VERSION
|
9
9
|
spec.authors = ['pyromaniac']
|
@@ -20,21 +20,19 @@ Gem::Specification.new do |spec|
|
|
20
20
|
|
21
21
|
spec.add_development_dependency 'rake'
|
22
22
|
spec.add_development_dependency 'appraisal'
|
23
|
-
spec.add_development_dependency 'rspec'
|
23
|
+
spec.add_development_dependency 'rspec'
|
24
24
|
spec.add_development_dependency 'rspec-its'
|
25
25
|
spec.add_development_dependency 'rspec-collection_matchers'
|
26
26
|
spec.add_development_dependency 'sqlite3'
|
27
27
|
spec.add_development_dependency 'database_cleaner'
|
28
28
|
spec.add_development_dependency 'elasticsearch-extensions'
|
29
29
|
spec.add_development_dependency 'resque_spec'
|
30
|
+
spec.add_development_dependency 'timecop'
|
31
|
+
spec.add_development_dependency 'rubocop'
|
30
32
|
spec.add_development_dependency 'rubysl', '~> 2.0' if RUBY_ENGINE == 'rbx'
|
31
33
|
|
32
34
|
spec.add_development_dependency 'method_source'
|
33
|
-
|
34
|
-
spec.add_development_dependency 'unparser', '0.2.4'
|
35
|
-
else
|
36
|
-
spec.add_development_dependency 'unparser'
|
37
|
-
end
|
35
|
+
spec.add_development_dependency 'unparser'
|
38
36
|
|
39
37
|
spec.add_dependency 'activesupport', '>= 3.2'
|
40
38
|
spec.add_dependency 'elasticsearch', '>= 1.0.0'
|
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
source "https://rubygems.org"
|
4
4
|
|
5
|
-
gem "mongoid", "
|
5
|
+
gem "mongoid", "~> 4.0.0"
|
6
6
|
gem "activesupport", "~> 4.2.0"
|
7
7
|
gem "resque", :require => false
|
8
8
|
gem "sidekiq", :require => false
|
@@ -10,6 +10,7 @@ gem "sidekiq", :require => false
|
|
10
10
|
group :test do
|
11
11
|
gem "guard"
|
12
12
|
gem "guard-rspec"
|
13
|
+
gem "listen", "~> 3.0.0"
|
13
14
|
end
|
14
15
|
|
15
16
|
gemspec :path => "../"
|
data/gemfiles/{rails.4.2.mongoid.4.0.0.kaminari.gemfile → rails.4.2.mongoid.4.0.kaminari.gemfile}
RENAMED
@@ -2,13 +2,14 @@
|
|
2
2
|
|
3
3
|
source "https://rubygems.org"
|
4
4
|
|
5
|
-
gem "mongoid", "
|
5
|
+
gem "mongoid", "~> 4.0.0"
|
6
6
|
gem "activesupport", "~> 4.2.0"
|
7
7
|
gem "kaminari", "0.16.3", :require => false
|
8
8
|
|
9
9
|
group :test do
|
10
10
|
gem "guard"
|
11
11
|
gem "guard-rspec"
|
12
|
+
gem "listen", "~> 3.0.0"
|
12
13
|
end
|
13
14
|
|
14
15
|
gemspec :path => "../"
|
@@ -2,13 +2,14 @@
|
|
2
2
|
|
3
3
|
source "https://rubygems.org"
|
4
4
|
|
5
|
-
gem "mongoid", "
|
5
|
+
gem "mongoid", "~> 4.0.0"
|
6
6
|
gem "activesupport", "~> 4.2.0"
|
7
7
|
gem "will_paginate", :require => false
|
8
8
|
|
9
9
|
group :test do
|
10
10
|
gem "guard"
|
11
11
|
gem "guard-rspec"
|
12
|
+
gem "listen", "~> 3.0.0"
|
12
13
|
end
|
13
14
|
|
14
15
|
gemspec :path => "../"
|
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
source "https://rubygems.org"
|
4
4
|
|
5
|
-
gem "mongoid", "
|
5
|
+
gem "mongoid", "~> 5.1.0"
|
6
6
|
gem "activesupport", "~> 4.2.0"
|
7
7
|
gem "resque", :require => false
|
8
8
|
gem "sidekiq", :require => false
|
@@ -10,6 +10,7 @@ gem "sidekiq", :require => false
|
|
10
10
|
group :test do
|
11
11
|
gem "guard"
|
12
12
|
gem "guard-rspec"
|
13
|
+
gem "listen", "~> 3.0.0"
|
13
14
|
end
|
14
15
|
|
15
16
|
gemspec :path => "../"
|
data/gemfiles/{rails.4.2.mongoid.5.1.0.kaminari.gemfile → rails.4.2.mongoid.5.1.kaminari.gemfile}
RENAMED
@@ -2,13 +2,14 @@
|
|
2
2
|
|
3
3
|
source "https://rubygems.org"
|
4
4
|
|
5
|
-
gem "mongoid", "
|
5
|
+
gem "mongoid", "~> 5.1.0"
|
6
6
|
gem "activesupport", "~> 4.2.0"
|
7
7
|
gem "kaminari", "0.16.3", :require => false
|
8
8
|
|
9
9
|
group :test do
|
10
10
|
gem "guard"
|
11
11
|
gem "guard-rspec"
|
12
|
+
gem "listen", "~> 3.0.0"
|
12
13
|
end
|
13
14
|
|
14
15
|
gemspec :path => "../"
|
@@ -2,13 +2,14 @@
|
|
2
2
|
|
3
3
|
source "https://rubygems.org"
|
4
4
|
|
5
|
-
gem "mongoid", "
|
5
|
+
gem "mongoid", "~> 5.1.0"
|
6
6
|
gem "activesupport", "~> 4.2.0"
|
7
7
|
gem "will_paginate", :require => false
|
8
8
|
|
9
9
|
group :test do
|
10
10
|
gem "guard"
|
11
11
|
gem "guard-rspec"
|
12
|
+
gem "listen", "~> 3.0.0"
|
12
13
|
end
|
13
14
|
|
14
15
|
gemspec :path => "../"
|
@@ -2,14 +2,16 @@
|
|
2
2
|
|
3
3
|
source "https://rubygems.org"
|
4
4
|
|
5
|
-
gem "activerecord", "~>
|
6
|
-
gem "activesupport", "~>
|
5
|
+
gem "activerecord", "~> 5.0.0"
|
6
|
+
gem "activesupport", "~> 5.0.0"
|
7
|
+
gem "activejob", "~> 5.0.0"
|
7
8
|
gem "resque", :require => false
|
8
9
|
gem "sidekiq", :require => false
|
9
10
|
|
10
11
|
group :test do
|
11
12
|
gem "guard"
|
12
13
|
gem "guard-rspec"
|
14
|
+
gem "listen", "~> 3.0.0"
|
13
15
|
end
|
14
16
|
|
15
17
|
gemspec :path => "../"
|
data/gemfiles/{rails.4.0.mongoid.4.0.0.kaminari.gemfile → rails.5.0.activerecord.kaminari.gemfile}
RENAMED
@@ -2,13 +2,15 @@
|
|
2
2
|
|
3
3
|
source "https://rubygems.org"
|
4
4
|
|
5
|
-
gem "
|
6
|
-
gem "activesupport", "~>
|
5
|
+
gem "activerecord", "~> 5.0.0"
|
6
|
+
gem "activesupport", "~> 5.0.0"
|
7
|
+
gem "activejob", "~> 5.0.0"
|
7
8
|
gem "kaminari", "0.16.3", :require => false
|
8
9
|
|
9
10
|
group :test do
|
10
11
|
gem "guard"
|
11
12
|
gem "guard-rspec"
|
13
|
+
gem "listen", "~> 3.0.0"
|
12
14
|
end
|
13
15
|
|
14
16
|
gemspec :path => "../"
|
@@ -2,13 +2,15 @@
|
|
2
2
|
|
3
3
|
source "https://rubygems.org"
|
4
4
|
|
5
|
-
gem "
|
6
|
-
gem "activesupport", "~>
|
5
|
+
gem "activerecord", "~> 5.0.0"
|
6
|
+
gem "activesupport", "~> 5.0.0"
|
7
|
+
gem "activejob", "~> 5.0.0"
|
7
8
|
gem "will_paginate", :require => false
|
8
9
|
|
9
10
|
group :test do
|
10
11
|
gem "guard"
|
11
12
|
gem "guard-rspec"
|
13
|
+
gem "listen", "~> 3.0.0"
|
12
14
|
end
|
13
15
|
|
14
16
|
gemspec :path => "../"
|
@@ -2,12 +2,13 @@
|
|
2
2
|
|
3
3
|
source "https://rubygems.org"
|
4
4
|
|
5
|
-
gem "sequel", "~> 4.
|
6
|
-
gem "activesupport", "~>
|
5
|
+
gem "sequel", "~> 4.38.0"
|
6
|
+
gem "activesupport", "~> 5.0.0"
|
7
7
|
|
8
8
|
group :test do
|
9
9
|
gem "guard"
|
10
10
|
gem "guard-rspec"
|
11
|
+
gem "listen", "~> 3.0.0"
|
11
12
|
end
|
12
13
|
|
13
14
|
gemspec :path => "../"
|
data/lib/chewy.rb
CHANGED
@@ -31,12 +31,14 @@ require 'chewy/index'
|
|
31
31
|
require 'chewy/type'
|
32
32
|
require 'chewy/fields/base'
|
33
33
|
require 'chewy/fields/root'
|
34
|
-
require 'chewy/
|
34
|
+
require 'chewy/journal'
|
35
|
+
require 'chewy/railtie' if defined?(::Rails::Railtie)
|
35
36
|
|
36
37
|
begin
|
37
38
|
require 'kaminari'
|
38
39
|
require 'chewy/query/pagination/kaminari'
|
39
40
|
rescue LoadError
|
41
|
+
nil
|
40
42
|
end
|
41
43
|
|
42
44
|
begin
|
@@ -44,6 +46,7 @@ begin
|
|
44
46
|
require 'will_paginate/collection'
|
45
47
|
require 'chewy/query/pagination/will_paginate'
|
46
48
|
rescue LoadError
|
49
|
+
nil
|
47
50
|
end
|
48
51
|
|
49
52
|
ActiveSupport.on_load(:active_record) do
|
@@ -52,23 +55,28 @@ ActiveSupport.on_load(:active_record) do
|
|
52
55
|
begin
|
53
56
|
require 'will_paginate/active_record'
|
54
57
|
rescue LoadError
|
58
|
+
nil
|
55
59
|
end
|
56
60
|
end
|
57
61
|
|
58
62
|
ActiveSupport.on_load(:mongoid) do
|
59
|
-
module Mongoid
|
60
|
-
|
63
|
+
module Mongoid
|
64
|
+
module Document
|
65
|
+
module ClassMethods
|
66
|
+
include Chewy::Type::Observe::MongoidMethods
|
67
|
+
end
|
68
|
+
end
|
61
69
|
end
|
62
70
|
|
63
71
|
begin
|
64
72
|
require 'will_paginate/mongoid'
|
65
73
|
require 'chewy/query/pagination/will_paginate'
|
66
74
|
rescue LoadError
|
75
|
+
nil
|
67
76
|
end
|
68
77
|
end
|
69
78
|
|
70
79
|
module Chewy
|
71
|
-
|
72
80
|
@adapters = [
|
73
81
|
Chewy::Type::Adapter::ActiveRecord,
|
74
82
|
Chewy::Type::Adapter::Mongoid,
|
@@ -89,34 +97,34 @@ module Chewy
|
|
89
97
|
#
|
90
98
|
# If index has more then one type - it raises Chewy::UnderivableType.
|
91
99
|
#
|
92
|
-
def derive_type
|
100
|
+
def derive_type(name)
|
93
101
|
return name if name.is_a?(Class) && name < Chewy::Type
|
94
102
|
|
95
103
|
index_name, type_name = name.split('#', 2)
|
96
104
|
class_name = "#{index_name.camelize}Index"
|
97
105
|
index = class_name.safe_constantize
|
98
|
-
raise Chewy::UnderivableType
|
99
|
-
|
100
|
-
index.type_hash[type_name] or raise Chewy::UnderivableType
|
106
|
+
raise Chewy::UnderivableType, "Can not find index named `#{class_name}`" unless index && index < Chewy::Index
|
107
|
+
if type_name.present?
|
108
|
+
index.type_hash[type_name] or raise Chewy::UnderivableType, "Index `#{class_name}` doesn`t have type named `#{type_name}`"
|
101
109
|
elsif index.types.one?
|
102
110
|
index.types.first
|
103
111
|
else
|
104
|
-
raise Chewy::UnderivableType
|
112
|
+
raise Chewy::UnderivableType, "Index `#{class_name}` has more than one type, please specify type via `#{index_name}#type_name`"
|
105
113
|
end
|
106
114
|
end
|
107
115
|
|
108
116
|
# Creates Chewy::Type ancestor defining index and adapter methods.
|
109
117
|
#
|
110
|
-
def create_type
|
118
|
+
def create_type(index, target, options = {}, &block)
|
111
119
|
type = Class.new(Chewy::Type)
|
112
120
|
|
113
|
-
adapter = adapters.find { |
|
121
|
+
adapter = adapters.find { |klass| klass.accepts?(target) }.new(target, options)
|
114
122
|
|
115
123
|
index.const_set(adapter.name, type)
|
116
124
|
type.send(:define_singleton_method, :index) { index }
|
117
125
|
type.send(:define_singleton_method, :adapter) { adapter }
|
118
126
|
|
119
|
-
type.class_eval
|
127
|
+
type.class_eval(&block) if block
|
120
128
|
type
|
121
129
|
end
|
122
130
|
|
@@ -144,7 +152,7 @@ module Chewy
|
|
144
152
|
# Be careful, if current prefix is blank, this will destroy all the indexes.
|
145
153
|
#
|
146
154
|
def massacre
|
147
|
-
Chewy.client.indices.delete(index: [Chewy.configuration[:prefix], '*'].delete_if(&:blank?).join(
|
155
|
+
Chewy.client.indices.delete(index: [Chewy.configuration[:prefix], '*'].delete_if(&:blank?).join('_'))
|
148
156
|
Chewy.wait_for_status
|
149
157
|
end
|
150
158
|
alias_method :delete_all, :massacre
|
@@ -172,7 +180,7 @@ module Chewy
|
|
172
180
|
# Chewy.strategy.pop
|
173
181
|
# city3.do_update! # index updated again
|
174
182
|
#
|
175
|
-
def strategy
|
183
|
+
def strategy(name = nil, &block)
|
176
184
|
Thread.current[:chewy_strategy] ||= Chewy::Strategy.new
|
177
185
|
if name
|
178
186
|
if block
|
@@ -188,11 +196,11 @@ module Chewy
|
|
188
196
|
def config
|
189
197
|
Chewy::Config.instance
|
190
198
|
end
|
191
|
-
delegate
|
199
|
+
delegate(*Chewy::Config.delegated, to: :config)
|
192
200
|
|
193
201
|
def repository
|
194
202
|
Chewy::Repository.instance
|
195
203
|
end
|
196
|
-
delegate
|
204
|
+
delegate(*Chewy::Repository.delegated, to: :repository)
|
197
205
|
end
|
198
206
|
end
|
data/lib/chewy/config.rb
CHANGED
@@ -36,10 +36,14 @@ module Chewy
|
|
36
36
|
# in tests with transactional fixtures or transactional
|
37
37
|
# DatabaseCleaner strategy.
|
38
38
|
#
|
39
|
-
:use_after_commit_callbacks
|
39
|
+
:use_after_commit_callbacks,
|
40
|
+
|
41
|
+
# Where Chewy expects to find index definitions
|
42
|
+
# within a Rails app folder.
|
43
|
+
:indices_path
|
40
44
|
|
41
45
|
def self.delegated
|
42
|
-
public_instance_methods -
|
46
|
+
public_instance_methods - superclass.public_instance_methods - Singleton.public_instance_methods
|
43
47
|
end
|
44
48
|
|
45
49
|
def initialize
|
@@ -49,14 +53,15 @@ module Chewy
|
|
49
53
|
@root_strategy = :base
|
50
54
|
@request_strategy = :atomic
|
51
55
|
@use_after_commit_callbacks = true
|
56
|
+
@indices_path = 'app/chewy'
|
52
57
|
end
|
53
58
|
|
54
|
-
def transport_logger=
|
59
|
+
def transport_logger=(logger)
|
55
60
|
Chewy.client.transport.logger = logger
|
56
61
|
@transport_logger = logger
|
57
62
|
end
|
58
63
|
|
59
|
-
def transport_tracer=
|
64
|
+
def transport_tracer=(tracer)
|
60
65
|
Chewy.client.transport.tracer = tracer
|
61
66
|
@transport_tracer = tracer
|
62
67
|
end
|
@@ -106,12 +111,13 @@ module Chewy
|
|
106
111
|
#
|
107
112
|
def configuration
|
108
113
|
yaml_settings.merge(settings.deep_symbolize_keys).tap do |configuration|
|
109
|
-
configuration
|
114
|
+
configuration[:logger] = transport_logger if transport_logger
|
115
|
+
configuration[:indices_path] ||= indices_path if indices_path
|
110
116
|
configuration.merge!(tracer: transport_tracer) if transport_tracer
|
111
117
|
end
|
112
118
|
end
|
113
119
|
|
114
|
-
def configuration=
|
120
|
+
def configuration=(options)
|
115
121
|
ActiveSupport::Deprecation.warn("`Chewy.configuration = {foo: 'bar'}` method is deprecated and will be removed soon, use `Chewy.settings = {foo: 'bar'}` method instead")
|
116
122
|
self.settings = options
|
117
123
|
end
|
@@ -121,7 +127,7 @@ module Chewy
|
|
121
127
|
def yaml_settings
|
122
128
|
@yaml_settings ||= begin
|
123
129
|
if defined?(Rails)
|
124
|
-
file = Rails.root.join(
|
130
|
+
file = Rails.root.join('config', 'chewy.yml')
|
125
131
|
|
126
132
|
if File.exist?(file)
|
127
133
|
yaml = ERB.new(File.read(file)).result
|