chewy 0.8.4 → 0.9.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (179) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +34 -0
  3. data/.rubocop_todo.yml +44 -0
  4. data/.travis.yml +20 -60
  5. data/Appraisals +15 -40
  6. data/CHANGELOG.md +42 -0
  7. data/Gemfile +1 -0
  8. data/Guardfile +5 -5
  9. data/README.md +155 -6
  10. data/Rakefile +11 -1
  11. data/chewy.gemspec +5 -7
  12. data/gemfiles/rails.3.2.activerecord.gemfile +1 -0
  13. data/gemfiles/rails.3.2.activerecord.kaminari.gemfile +1 -0
  14. data/gemfiles/rails.3.2.activerecord.will_paginate.gemfile +1 -0
  15. data/gemfiles/rails.4.2.activerecord.gemfile +1 -0
  16. data/gemfiles/rails.4.2.activerecord.kaminari.gemfile +1 -0
  17. data/gemfiles/rails.4.2.activerecord.will_paginate.gemfile +1 -0
  18. data/gemfiles/{rails.4.2.mongoid.4.0.0.gemfile → rails.4.2.mongoid.4.0.gemfile} +2 -1
  19. data/gemfiles/{rails.4.2.mongoid.4.0.0.kaminari.gemfile → rails.4.2.mongoid.4.0.kaminari.gemfile} +2 -1
  20. data/gemfiles/{rails.4.2.mongoid.4.0.0.will_paginate.gemfile → rails.4.2.mongoid.4.0.will_paginate.gemfile} +2 -1
  21. data/gemfiles/{rails.4.2.mongoid.5.1.0.gemfile → rails.4.2.mongoid.5.1.gemfile} +2 -1
  22. data/gemfiles/{rails.4.2.mongoid.5.1.0.kaminari.gemfile → rails.4.2.mongoid.5.1.kaminari.gemfile} +2 -1
  23. data/gemfiles/{rails.4.2.mongoid.5.1.0.will_paginate.gemfile → rails.4.2.mongoid.5.1.will_paginate.gemfile} +2 -1
  24. data/gemfiles/{rails.4.0.activerecord.gemfile → rails.5.0.activerecord.gemfile} +4 -2
  25. data/gemfiles/{rails.4.0.mongoid.4.0.0.kaminari.gemfile → rails.5.0.activerecord.kaminari.gemfile} +4 -2
  26. data/gemfiles/{rails.4.0.mongoid.4.0.0.will_paginate.gemfile → rails.5.0.activerecord.will_paginate.gemfile} +4 -2
  27. data/gemfiles/{sequel.4.31.gemfile → sequel.4.38.gemfile} +3 -2
  28. data/lib/chewy.rb +24 -16
  29. data/lib/chewy/backports/deep_dup.rb +1 -1
  30. data/lib/chewy/backports/duplicable.rb +1 -0
  31. data/lib/chewy/config.rb +13 -7
  32. data/lib/chewy/errors.rb +4 -4
  33. data/lib/chewy/fields/base.rb +19 -14
  34. data/lib/chewy/fields/root.rb +11 -9
  35. data/lib/chewy/index.rb +38 -25
  36. data/lib/chewy/index/actions.rb +17 -17
  37. data/lib/chewy/index/settings.rb +3 -4
  38. data/lib/chewy/journal.rb +107 -0
  39. data/lib/chewy/journal/apply.rb +31 -0
  40. data/lib/chewy/journal/clean.rb +24 -0
  41. data/lib/chewy/journal/entry.rb +83 -0
  42. data/lib/chewy/journal/query.rb +87 -0
  43. data/lib/chewy/log_subscriber.rb +8 -8
  44. data/lib/chewy/minitest.rb +1 -0
  45. data/lib/chewy/minitest/helpers.rb +77 -0
  46. data/lib/chewy/minitest/search_index_receiver.rb +80 -0
  47. data/lib/chewy/query.rb +116 -60
  48. data/lib/chewy/query/compose.rb +5 -6
  49. data/lib/chewy/query/criteria.rb +26 -16
  50. data/lib/chewy/query/filters.rb +9 -9
  51. data/lib/chewy/query/loading.rb +2 -2
  52. data/lib/chewy/query/nodes/and.rb +3 -3
  53. data/lib/chewy/query/nodes/base.rb +1 -1
  54. data/lib/chewy/query/nodes/bool.rb +6 -4
  55. data/lib/chewy/query/nodes/equal.rb +6 -6
  56. data/lib/chewy/query/nodes/exists.rb +2 -2
  57. data/lib/chewy/query/nodes/expr.rb +2 -2
  58. data/lib/chewy/query/nodes/field.rb +35 -31
  59. data/lib/chewy/query/nodes/has_child.rb +1 -0
  60. data/lib/chewy/query/nodes/has_parent.rb +1 -0
  61. data/lib/chewy/query/nodes/has_relation.rb +11 -13
  62. data/lib/chewy/query/nodes/match_all.rb +1 -1
  63. data/lib/chewy/query/nodes/missing.rb +2 -2
  64. data/lib/chewy/query/nodes/not.rb +3 -3
  65. data/lib/chewy/query/nodes/or.rb +3 -3
  66. data/lib/chewy/query/nodes/prefix.rb +4 -3
  67. data/lib/chewy/query/nodes/query.rb +3 -3
  68. data/lib/chewy/query/nodes/range.rb +11 -11
  69. data/lib/chewy/query/nodes/raw.rb +1 -1
  70. data/lib/chewy/query/nodes/regexp.rb +15 -11
  71. data/lib/chewy/query/nodes/script.rb +6 -6
  72. data/lib/chewy/query/pagination/will_paginate.rb +2 -2
  73. data/lib/chewy/railtie.rb +3 -3
  74. data/lib/chewy/rake_helper.rb +51 -30
  75. data/lib/chewy/repository.rb +2 -2
  76. data/lib/chewy/rspec.rb +1 -1
  77. data/lib/chewy/rspec/update_index.rb +46 -47
  78. data/lib/chewy/runtime/version.rb +4 -4
  79. data/lib/chewy/search.rb +7 -5
  80. data/lib/chewy/strategy.rb +10 -8
  81. data/lib/chewy/strategy/atomic.rb +2 -2
  82. data/lib/chewy/strategy/base.rb +4 -4
  83. data/lib/chewy/strategy/bypass.rb +1 -2
  84. data/lib/chewy/strategy/sidekiq.rb +2 -0
  85. data/lib/chewy/strategy/urgent.rb +1 -1
  86. data/lib/chewy/type.rb +51 -45
  87. data/lib/chewy/type/adapter/active_record.rb +23 -12
  88. data/lib/chewy/type/adapter/base.rb +4 -4
  89. data/lib/chewy/type/adapter/mongoid.rb +6 -6
  90. data/lib/chewy/type/adapter/object.rb +15 -12
  91. data/lib/chewy/type/adapter/orm.rb +24 -15
  92. data/lib/chewy/type/adapter/sequel.rb +11 -7
  93. data/lib/chewy/type/crutch.rb +4 -3
  94. data/lib/chewy/type/import.rb +51 -32
  95. data/lib/chewy/type/mapping.rb +17 -17
  96. data/lib/chewy/type/observe.rb +9 -7
  97. data/lib/chewy/type/witchcraft.rb +62 -23
  98. data/lib/chewy/type/wrapper.rb +20 -14
  99. data/lib/chewy/version.rb +1 -1
  100. data/lib/generators/chewy/install_generator.rb +3 -3
  101. data/lib/tasks/chewy.rake +28 -23
  102. data/spec/chewy/config_spec.rb +33 -12
  103. data/spec/chewy/fields/base_spec.rb +143 -154
  104. data/spec/chewy/fields/root_spec.rb +22 -20
  105. data/spec/chewy/fields/time_fields_spec.rb +11 -9
  106. data/spec/chewy/index/actions_spec.rb +27 -4
  107. data/spec/chewy/index/aliases_spec.rb +2 -2
  108. data/spec/chewy/index/settings_spec.rb +72 -50
  109. data/spec/chewy/index_spec.rb +95 -43
  110. data/spec/chewy/journal/apply_spec.rb +120 -0
  111. data/spec/chewy/journal/entry_spec.rb +237 -0
  112. data/spec/chewy/journal_spec.rb +173 -0
  113. data/spec/chewy/minitest/helpers_spec.rb +90 -0
  114. data/spec/chewy/minitest/search_index_receiver_spec.rb +120 -0
  115. data/spec/chewy/query/criteria_spec.rb +504 -237
  116. data/spec/chewy/query/filters_spec.rb +94 -66
  117. data/spec/chewy/query/loading_spec.rb +76 -40
  118. data/spec/chewy/query/nodes/and_spec.rb +3 -7
  119. data/spec/chewy/query/nodes/bool_spec.rb +5 -13
  120. data/spec/chewy/query/nodes/equal_spec.rb +20 -20
  121. data/spec/chewy/query/nodes/exists_spec.rb +7 -7
  122. data/spec/chewy/query/nodes/has_child_spec.rb +42 -23
  123. data/spec/chewy/query/nodes/has_parent_spec.rb +42 -23
  124. data/spec/chewy/query/nodes/match_all_spec.rb +2 -2
  125. data/spec/chewy/query/nodes/missing_spec.rb +6 -5
  126. data/spec/chewy/query/nodes/not_spec.rb +3 -7
  127. data/spec/chewy/query/nodes/or_spec.rb +3 -7
  128. data/spec/chewy/query/nodes/prefix_spec.rb +6 -6
  129. data/spec/chewy/query/nodes/query_spec.rb +3 -3
  130. data/spec/chewy/query/nodes/range_spec.rb +19 -19
  131. data/spec/chewy/query/nodes/raw_spec.rb +2 -2
  132. data/spec/chewy/query/nodes/regexp_spec.rb +31 -19
  133. data/spec/chewy/query/nodes/script_spec.rb +5 -5
  134. data/spec/chewy/query/pagination/kaminari_spec.rb +2 -2
  135. data/spec/chewy/query/pagination/will_paginage_spec.rb +6 -7
  136. data/spec/chewy/query/pagination_spec.rb +2 -3
  137. data/spec/chewy/query_spec.rb +208 -145
  138. data/spec/chewy/repository_spec.rb +8 -8
  139. data/spec/chewy/rspec/update_index_spec.rb +180 -111
  140. data/spec/chewy/search_spec.rb +8 -8
  141. data/spec/chewy/strategy/active_job_spec.rb +2 -2
  142. data/spec/chewy/strategy/atomic_spec.rb +4 -1
  143. data/spec/chewy/strategy/resque_spec.rb +2 -2
  144. data/spec/chewy/strategy/sidekiq_spec.rb +2 -2
  145. data/spec/chewy/type/actions_spec.rb +1 -1
  146. data/spec/chewy/type/adapter/active_record_spec.rb +255 -149
  147. data/spec/chewy/type/adapter/mongoid_spec.rb +169 -108
  148. data/spec/chewy/type/adapter/object_spec.rb +56 -40
  149. data/spec/chewy/type/adapter/sequel_spec.rb +248 -163
  150. data/spec/chewy/type/import_spec.rb +78 -47
  151. data/spec/chewy/type/mapping_spec.rb +6 -6
  152. data/spec/chewy/type/observe_spec.rb +20 -14
  153. data/spec/chewy/type/witchcraft_spec.rb +89 -43
  154. data/spec/chewy/type_spec.rb +4 -3
  155. data/spec/chewy_spec.rb +10 -8
  156. data/spec/spec_helper.rb +3 -0
  157. data/spec/support/active_record.rb +1 -1
  158. data/spec/support/class_helpers.rb +10 -11
  159. data/spec/support/mongoid.rb +2 -2
  160. data/spec/support/sequel.rb +1 -1
  161. metadata +65 -35
  162. data/gemfiles/rails.4.0.activerecord.kaminari.gemfile +0 -14
  163. data/gemfiles/rails.4.0.activerecord.will_paginate.gemfile +0 -14
  164. data/gemfiles/rails.4.0.mongoid.4.0.0.gemfile +0 -15
  165. data/gemfiles/rails.4.0.mongoid.5.1.0.gemfile +0 -15
  166. data/gemfiles/rails.4.0.mongoid.5.1.0.kaminari.gemfile +0 -14
  167. data/gemfiles/rails.4.0.mongoid.5.1.0.will_paginate.gemfile +0 -14
  168. data/gemfiles/rails.4.1.activerecord.gemfile +0 -15
  169. data/gemfiles/rails.4.1.activerecord.kaminari.gemfile +0 -14
  170. data/gemfiles/rails.4.1.activerecord.will_paginate.gemfile +0 -14
  171. data/gemfiles/rails.4.1.mongoid.4.0.0.gemfile +0 -15
  172. data/gemfiles/rails.4.1.mongoid.4.0.0.kaminari.gemfile +0 -14
  173. data/gemfiles/rails.4.1.mongoid.4.0.0.will_paginate.gemfile +0 -14
  174. data/gemfiles/rails.4.1.mongoid.5.1.0.gemfile +0 -15
  175. data/gemfiles/rails.4.1.mongoid.5.1.0.kaminari.gemfile +0 -14
  176. data/gemfiles/rails.4.1.mongoid.5.1.0.will_paginate.gemfile +0 -14
  177. data/gemfiles/rails.5.0.0.beta3.activerecord.gemfile +0 -16
  178. data/gemfiles/rails.5.0.0.beta3.activerecord.kaminari.gemfile +0 -16
  179. 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 :default => :spec
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
@@ -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', '~> 3.4.0'
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
- if RUBY_VERSION < '2.1.0'
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'
@@ -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 => "../"
@@ -9,6 +9,7 @@ gem "kaminari", "0.16.3", :require => false
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 => "../"
@@ -9,6 +9,7 @@ gem "will_paginate", :require => false
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 => "../"
@@ -11,6 +11,7 @@ gem "sidekiq", :require => false
11
11
  group :test do
12
12
  gem "guard"
13
13
  gem "guard-rspec"
14
+ gem "listen", "~> 3.0.0"
14
15
  end
15
16
 
16
17
  gemspec :path => "../"
@@ -10,6 +10,7 @@ gem "kaminari", "0.16.3", :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 => "../"
@@ -10,6 +10,7 @@ gem "will_paginate", :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 => "../"
@@ -2,7 +2,7 @@
2
2
 
3
3
  source "https://rubygems.org"
4
4
 
5
- gem "mongoid", "> 4.0.0"
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 => "../"
@@ -2,13 +2,14 @@
2
2
 
3
3
  source "https://rubygems.org"
4
4
 
5
- gem "mongoid", "> 4.0.0"
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", "> 4.0.0"
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.1.0"
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 => "../"
@@ -2,13 +2,14 @@
2
2
 
3
3
  source "https://rubygems.org"
4
4
 
5
- gem "mongoid", "> 5.1.0"
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.1.0"
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", "~> 4.0.0"
6
- gem "activesupport", "~> 4.0.0"
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 => "../"
@@ -2,13 +2,15 @@
2
2
 
3
3
  source "https://rubygems.org"
4
4
 
5
- gem "mongoid", "> 4.0.0"
6
- gem "activesupport", "~> 4.0.0"
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 "mongoid", "> 4.0.0"
6
- gem "activesupport", "~> 4.0.0"
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.31.0"
6
- gem "activesupport", "~> 4.2.0"
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 => "../"
@@ -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/railtie' if defined?(::Rails)
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::Document::ClassMethods
60
- include Chewy::Type::Observe::MongoidMethods
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 name
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.new("Can not find index named `#{class_name}`") unless index && index < Chewy::Index
99
- type = if type_name.present?
100
- index.type_hash[type_name] or raise Chewy::UnderivableType.new("Index `#{class_name}` doesn`t have type named `#{type_name}`")
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.new("Index `#{class_name}` has more than one type, please specify type via `#{index_name}#type_name`")
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 index, target, options = {}, &block
118
+ def create_type(index, target, options = {}, &block)
111
119
  type = Class.new(Chewy::Type)
112
120
 
113
- adapter = adapters.find { |adapter| adapter.accepts?(target) }.new(target, options)
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 &block if block
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 name = nil, &block
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 *Chewy::Config.delegated, to: :config
199
+ delegate(*Chewy::Config.delegated, to: :config)
192
200
 
193
201
  def repository
194
202
  Chewy::Repository.instance
195
203
  end
196
- delegate *Chewy::Repository.delegated, to: :repository
204
+ delegate(*Chewy::Repository.delegated, to: :repository)
197
205
  end
198
206
  end
@@ -25,7 +25,7 @@ class Array
25
25
  # array[1][2] # => nil
26
26
  # dup[1][2] # => 4
27
27
  def deep_dup
28
- map { |it| it.deep_dup }
28
+ map(&:deep_dup)
29
29
  end
30
30
  end
31
31
 
@@ -86,5 +86,6 @@ class BigDecimal
86
86
  end
87
87
  rescue TypeError
88
88
  # can't dup, so use superclass implementation
89
+ nil
89
90
  end
90
91
  end
@@ -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 - self.superclass.public_instance_methods - Singleton.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= 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= 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.merge!(logger: transport_logger) if transport_logger
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= options
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(*%w(config chewy.yml))
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