chewy 7.1.0 → 7.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (131) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/ruby.yml +58 -0
  3. data/.rubocop.yml +13 -8
  4. data/.rubocop_todo.yml +110 -22
  5. data/CHANGELOG.md +53 -0
  6. data/Gemfile +0 -7
  7. data/Guardfile +3 -1
  8. data/README.md +282 -245
  9. data/chewy.gemspec +3 -5
  10. data/gemfiles/rails.5.2.activerecord.gemfile +8 -14
  11. data/gemfiles/rails.6.0.activerecord.gemfile +8 -14
  12. data/gemfiles/rails.6.1.activerecord.gemfile +8 -14
  13. data/lib/chewy.rb +21 -75
  14. data/lib/chewy/config.rb +40 -40
  15. data/lib/chewy/errors.rb +0 -12
  16. data/lib/chewy/fields/base.rb +11 -1
  17. data/lib/chewy/fields/root.rb +3 -4
  18. data/lib/chewy/index.rb +46 -87
  19. data/lib/chewy/index/actions.rb +51 -32
  20. data/lib/chewy/{type → index}/adapter/active_record.rb +12 -3
  21. data/lib/chewy/{type → index}/adapter/base.rb +2 -3
  22. data/lib/chewy/{type → index}/adapter/object.rb +27 -31
  23. data/lib/chewy/{type → index}/adapter/orm.rb +11 -14
  24. data/lib/chewy/{type → index}/crutch.rb +5 -5
  25. data/lib/chewy/{type → index}/import.rb +36 -27
  26. data/lib/chewy/{type → index}/import/bulk_builder.rb +15 -13
  27. data/lib/chewy/{type → index}/import/bulk_request.rb +6 -6
  28. data/lib/chewy/{type → index}/import/journal_builder.rb +10 -10
  29. data/lib/chewy/{type → index}/import/routine.rb +15 -14
  30. data/lib/chewy/{type → index}/mapping.rb +26 -31
  31. data/lib/chewy/{type → index}/observe.rb +9 -19
  32. data/lib/chewy/index/specification.rb +1 -0
  33. data/lib/chewy/{type → index}/syncer.rb +60 -57
  34. data/lib/chewy/{type → index}/witchcraft.rb +11 -7
  35. data/lib/chewy/{type → index}/wrapper.rb +2 -2
  36. data/lib/chewy/journal.rb +8 -8
  37. data/lib/chewy/minitest/helpers.rb +9 -13
  38. data/lib/chewy/minitest/search_index_receiver.rb +22 -26
  39. data/lib/chewy/railtie.rb +4 -2
  40. data/lib/chewy/rake_helper.rb +82 -107
  41. data/lib/chewy/rspec/update_index.rb +47 -43
  42. data/lib/chewy/search.rb +4 -17
  43. data/lib/chewy/search/loader.rb +18 -30
  44. data/lib/chewy/search/parameters.rb +4 -2
  45. data/lib/chewy/search/parameters/concerns/query_storage.rb +2 -2
  46. data/lib/chewy/search/parameters/source.rb +5 -1
  47. data/lib/chewy/search/query_proxy.rb +9 -2
  48. data/lib/chewy/search/request.rb +82 -86
  49. data/lib/chewy/search/response.rb +4 -4
  50. data/lib/chewy/search/scoping.rb +6 -7
  51. data/lib/chewy/search/scrolling.rb +11 -11
  52. data/lib/chewy/stash.rb +14 -22
  53. data/lib/chewy/strategy.rb +3 -19
  54. data/lib/chewy/strategy/sidekiq.rb +1 -0
  55. data/lib/chewy/version.rb +1 -1
  56. data/lib/generators/chewy/install_generator.rb +1 -1
  57. data/lib/tasks/chewy.rake +10 -22
  58. data/migration_guide.md +14 -0
  59. data/spec/chewy/config_spec.rb +14 -39
  60. data/spec/chewy/fields/base_spec.rb +412 -148
  61. data/spec/chewy/fields/root_spec.rb +16 -24
  62. data/spec/chewy/fields/time_fields_spec.rb +5 -5
  63. data/spec/chewy/index/actions_spec.rb +270 -24
  64. data/spec/chewy/{type → index}/adapter/active_record_spec.rb +68 -40
  65. data/spec/chewy/{type → index}/adapter/object_spec.rb +21 -6
  66. data/spec/chewy/{type → index}/import/bulk_builder_spec.rb +23 -31
  67. data/spec/chewy/{type → index}/import/bulk_request_spec.rb +5 -6
  68. data/spec/chewy/{type → index}/import/journal_builder_spec.rb +9 -15
  69. data/spec/chewy/{type → index}/import/routine_spec.rb +16 -16
  70. data/spec/chewy/{type → index}/import_spec.rb +102 -98
  71. data/spec/chewy/{type → index}/mapping_spec.rb +46 -54
  72. data/spec/chewy/index/observe_spec.rb +116 -0
  73. data/spec/chewy/index/settings_spec.rb +3 -1
  74. data/spec/chewy/index/specification_spec.rb +7 -17
  75. data/spec/chewy/{type → index}/syncer_spec.rb +14 -19
  76. data/spec/chewy/{type → index}/witchcraft_spec.rb +20 -22
  77. data/spec/chewy/index/wrapper_spec.rb +100 -0
  78. data/spec/chewy/index_spec.rb +59 -102
  79. data/spec/chewy/journal_spec.rb +9 -22
  80. data/spec/chewy/minitest/helpers_spec.rb +13 -15
  81. data/spec/chewy/minitest/search_index_receiver_spec.rb +22 -26
  82. data/spec/chewy/multi_search_spec.rb +4 -5
  83. data/spec/chewy/rake_helper_spec.rb +145 -55
  84. data/spec/chewy/rspec/update_index_spec.rb +74 -71
  85. data/spec/chewy/search/loader_spec.rb +19 -37
  86. data/spec/chewy/search/pagination/kaminari_examples.rb +3 -5
  87. data/spec/chewy/search/pagination/kaminari_spec.rb +1 -1
  88. data/spec/chewy/search/parameters/indices_spec.rb +2 -8
  89. data/spec/chewy/search/parameters/order_spec.rb +1 -1
  90. data/spec/chewy/search/parameters/query_storage_examples.rb +67 -21
  91. data/spec/chewy/search/parameters/search_after_spec.rb +4 -1
  92. data/spec/chewy/search/parameters/source_spec.rb +8 -2
  93. data/spec/chewy/search/parameters_spec.rb +12 -3
  94. data/spec/chewy/search/query_proxy_spec.rb +68 -17
  95. data/spec/chewy/search/request_spec.rb +222 -74
  96. data/spec/chewy/search/response_spec.rb +12 -12
  97. data/spec/chewy/search/scrolling_spec.rb +7 -9
  98. data/spec/chewy/search_spec.rb +32 -35
  99. data/spec/chewy/stash_spec.rb +9 -21
  100. data/spec/chewy/strategy/active_job_spec.rb +8 -8
  101. data/spec/chewy/strategy/atomic_spec.rb +9 -10
  102. data/spec/chewy/strategy/sidekiq_spec.rb +8 -8
  103. data/spec/chewy/strategy_spec.rb +19 -15
  104. data/spec/chewy_spec.rb +14 -100
  105. data/spec/spec_helper.rb +2 -21
  106. data/spec/support/active_record.rb +15 -5
  107. metadata +44 -103
  108. data/.circleci/config.yml +0 -214
  109. data/Appraisals +0 -81
  110. data/gemfiles/rails.5.2.mongoid.6.4.gemfile +0 -17
  111. data/gemfiles/sequel.4.45.gemfile +0 -11
  112. data/lib/chewy/search/pagination/will_paginate.rb +0 -43
  113. data/lib/chewy/strategy/resque.rb +0 -27
  114. data/lib/chewy/strategy/shoryuken.rb +0 -40
  115. data/lib/chewy/type.rb +0 -120
  116. data/lib/chewy/type/actions.rb +0 -43
  117. data/lib/chewy/type/adapter/mongoid.rb +0 -67
  118. data/lib/chewy/type/adapter/sequel.rb +0 -93
  119. data/lib/sequel/plugins/chewy_observe.rb +0 -63
  120. data/spec/chewy/search/pagination/will_paginate_examples.rb +0 -63
  121. data/spec/chewy/search/pagination/will_paginate_spec.rb +0 -23
  122. data/spec/chewy/strategy/resque_spec.rb +0 -46
  123. data/spec/chewy/strategy/shoryuken_spec.rb +0 -70
  124. data/spec/chewy/type/actions_spec.rb +0 -50
  125. data/spec/chewy/type/adapter/mongoid_spec.rb +0 -372
  126. data/spec/chewy/type/adapter/sequel_spec.rb +0 -472
  127. data/spec/chewy/type/observe_spec.rb +0 -137
  128. data/spec/chewy/type/wrapper_spec.rb +0 -100
  129. data/spec/chewy/type_spec.rb +0 -55
  130. data/spec/support/mongoid.rb +0 -93
  131. data/spec/support/sequel.rb +0 -80
data/.circleci/config.yml DELETED
@@ -1,214 +0,0 @@
1
- # Check https://circleci.com/docs/2.0/language-ruby/ for more details
2
- version: 2.1
3
-
4
- es-env: &es-env
5
- cluster.name: elasticsearch
6
- transport.host: localhost
7
- network.host: 127.0.0.1
8
- http.port: 9250
9
- discovery.type: single-node
10
- xpack.security.enabled: false
11
- xpack.monitoring.enabled: false
12
-
13
- workflows:
14
- build:
15
- jobs:
16
- - rubocop
17
- - rspec-ruby-26-activerecord61
18
- - rspec-ruby-26-activerecord60
19
- - rspec-ruby-26-activerecord52
20
- - rspec-ruby-26-mongoid
21
- - rspec-ruby-27-activerecord61
22
- - rspec-ruby-27-activerecord60
23
- - rspec-ruby-27-activerecord52
24
- - rspec-ruby-27-mongoid
25
- - rspec-ruby-30-activerecord61
26
-
27
- commands:
28
- rspec-test:
29
- description: Test rspec in current ruby
30
- parameters:
31
- pre-steps:
32
- description: Necessary steps after checkout
33
- type: steps
34
- default: []
35
- steps:
36
- - checkout
37
- - run:
38
- name: ruby version
39
- command: |
40
- ruby -e "STDERR.puts RUBY_VERSION; puts RUBY_VERSION.gsub(/^(\d+)\.(\d+)\..*/, '\1_\2')" > .ruby.version
41
- - run:
42
- name: Gemfile.lock version
43
- command: |
44
- echo "$GEMFILE.lock" > .Gemfile.lock.path
45
- - steps: << parameters.pre-steps >>
46
- - restore_cache:
47
- keys:
48
- - dependencies-{{ checksum ".ruby.version" }}-{{ checksum ".Gemfile.lock.path" }}
49
- - run:
50
- name: install dependencies
51
- command: |
52
- bundle install --jobs=4 --retry=3 --path vendor/bundle --gemfile=$GEMFILE
53
- - save_cache:
54
- paths:
55
- - ./vendor/bundle
56
- key: dependencies-{{ checksum ".ruby.version" }}-{{ checksum ".Gemfile.lock.path" }}
57
- - run:
58
- name: Disable replication of elastic indices
59
- command: |
60
- curl -XPUT 'http://localhost:9250/_all/_settings?preserve_existing=true' -d '{
61
- "index.number_of_replicas":"0"
62
- }'
63
- - run:
64
- name: run tests
65
- command: |
66
- ruby -v
67
- git config --global user.email "you@example.com"
68
- git config --global user.name "Your Name"
69
- mkdir /tmp/test-results
70
- TEST_FILES="$(circleci tests glob "spec/**/*_spec.rb" | circleci tests split --split-by=timings)"
71
- BUNDLE_GEMFILE=$GEMFILE bundle exec rspec --format progress --format RspecJunitFormatter --out /tmp/test-results/rspec.xml $TEST_FILES
72
- - store_test_results:
73
- path: /tmp/test-results
74
-
75
- jobs:
76
- rubocop:
77
- docker:
78
- - image: circleci/ruby:2.6
79
- working_directory: ~/repo
80
- steps:
81
- - checkout
82
- - run:
83
- name: ruby version
84
- command: |
85
- ruby -e "STDERR.puts RUBY_VERSION; puts RUBY_VERSION.gsub(/^(\d+)\.(\d+)\..*/, '\1_\2')" > .ruby.version
86
- - run:
87
- name: Gemfile.lock version
88
- command: |
89
- echo "$GEMFILE.lock" > .Gemfile.lock.path
90
- - restore_cache:
91
- keys:
92
- - dependencies-{{ checksum ".ruby.version" }}-{{ checksum ".Gemfile.lock.path" }}
93
- - run:
94
- name: install dependencies
95
- command: |
96
- bundle install --jobs=4 --retry=3 --path vendor/bundle --binstubs=/usr/local/bundle/bin
97
- - save_cache:
98
- paths:
99
- - ./vendor/bundle
100
- key: dependencies-{{ checksum ".ruby.version" }}-{{ checksum ".Gemfile.lock.path" }}
101
- - run:
102
- name: run rubocop
103
- command: |
104
- bundle exec rubocop --format simple
105
-
106
- rspec-ruby-26-activerecord52:
107
- docker:
108
- - image: circleci/ruby:2.6
109
- - image: docker.elastic.co/elasticsearch/elasticsearch:7.10.1
110
- environment:
111
- <<: *es-env
112
- working_directory: ~/repo
113
- environment:
114
- GEMFILE: gemfiles/rails.5.2.activerecord.gemfile
115
- steps:
116
- - rspec-test
117
-
118
- rspec-ruby-26-activerecord60:
119
- docker:
120
- - image: circleci/ruby:2.6
121
- - image: docker.elastic.co/elasticsearch/elasticsearch:7.10.1
122
- environment:
123
- <<: *es-env
124
- working_directory: ~/repo
125
- environment:
126
- GEMFILE: gemfiles/rails.6.0.activerecord.gemfile
127
- steps:
128
- - rspec-test
129
-
130
- rspec-ruby-26-activerecord61:
131
- docker:
132
- - image: circleci/ruby:2.6
133
- - image: docker.elastic.co/elasticsearch/elasticsearch:7.10.1
134
- environment:
135
- <<: *es-env
136
- working_directory: ~/repo
137
- environment:
138
- GEMFILE: gemfiles/rails.6.1.activerecord.gemfile
139
- steps:
140
- - rspec-test
141
-
142
- rspec-ruby-26-mongoid:
143
- docker:
144
- - image: circleci/ruby:2.6
145
- - image: circleci/mongo:4.2.5
146
- - image: docker.elastic.co/elasticsearch/elasticsearch:7.10.1
147
- environment:
148
- <<: *es-env
149
- working_directory: ~/repo
150
- environment:
151
- GEMFILE: gemfiles/rails.5.2.mongoid.6.4.gemfile
152
- steps:
153
- - rspec-test
154
-
155
- rspec-ruby-27-activerecord52:
156
- docker:
157
- - image: circleci/ruby:2.7
158
- - image: docker.elastic.co/elasticsearch/elasticsearch:7.10.1
159
- environment:
160
- <<: *es-env
161
- working_directory: ~/repo
162
- environment:
163
- GEMFILE: gemfiles/rails.5.2.activerecord.gemfile
164
- steps:
165
- - rspec-test
166
-
167
- rspec-ruby-27-activerecord60:
168
- docker:
169
- - image: circleci/ruby:2.7
170
- - image: docker.elastic.co/elasticsearch/elasticsearch:7.10.1
171
- environment:
172
- <<: *es-env
173
- working_directory: ~/repo
174
- environment:
175
- GEMFILE: gemfiles/rails.6.0.activerecord.gemfile
176
- steps:
177
- - rspec-test
178
-
179
- rspec-ruby-27-activerecord61:
180
- docker:
181
- - image: circleci/ruby:2.7
182
- - image: docker.elastic.co/elasticsearch/elasticsearch:7.10.1
183
- environment:
184
- <<: *es-env
185
- working_directory: ~/repo
186
- environment:
187
- GEMFILE: gemfiles/rails.6.1.activerecord.gemfile
188
- steps:
189
- - rspec-test
190
-
191
- rspec-ruby-27-mongoid:
192
- docker:
193
- - image: circleci/ruby:2.7
194
- - image: circleci/mongo:4.2.5
195
- - image: docker.elastic.co/elasticsearch/elasticsearch:7.10.1
196
- environment:
197
- <<: *es-env
198
- working_directory: ~/repo
199
- environment:
200
- GEMFILE: gemfiles/rails.5.2.mongoid.6.4.gemfile
201
- steps:
202
- - rspec-test
203
-
204
- rspec-ruby-30-activerecord61:
205
- docker:
206
- - image: circleci/ruby:3.0
207
- - image: docker.elastic.co/elasticsearch/elasticsearch:7.10.1
208
- environment:
209
- <<: *es-env
210
- working_directory: ~/repo
211
- environment:
212
- GEMFILE: gemfiles/rails.6.1.activerecord.gemfile
213
- steps:
214
- - rspec-test
data/Appraisals DELETED
@@ -1,81 +0,0 @@
1
- %w[4.0 4.1 4.2].each do |activesupport|
2
- appraise "rails.#{activesupport}.activerecord" do
3
- gem 'activerecord', "~> #{activesupport}.0"
4
- gem 'activesupport', "~> #{activesupport}.0"
5
-
6
- gem 'activejob', "~> #{activesupport}.0" if activesupport >= '4.2'
7
- gem 'resque', require: false
8
- gem 'shoryuken', require: false
9
- gem 'aws-sdk-sqs', require: false
10
- gem 'sidekiq', require: false
11
-
12
- gem 'kaminari', '~> 0.17.0', require: false
13
- gem 'will_paginate', require: false
14
-
15
- gem 'parallel', require: false
16
- end
17
- end
18
-
19
- %w[5.0 5.1 5.2].each do |activesupport|
20
- appraise "rails.#{activesupport}.activerecord" do
21
- gem 'activerecord', "~> #{activesupport}.0"
22
- gem 'activesupport', "~> #{activesupport}.0"
23
-
24
- gem 'activejob', "~> #{activesupport}.0"
25
- gem 'resque', require: false
26
- gem 'shoryuken', require: false
27
- gem 'aws-sdk-sqs', require: false
28
- gem 'sidekiq', require: false
29
-
30
- gem 'kaminari-core', '~> 1.1.0', require: false
31
- gem 'will_paginate', require: false
32
-
33
- gem 'parallel', require: false
34
- end
35
- end
36
-
37
- appraise 'rails.4.2.mongoid.5.2' do
38
- gem 'mongoid', '~> 5.2.0'
39
- gem 'activesupport', '~> 4.2.0'
40
-
41
- gem 'activejob', '~> 4.2.0'
42
- gem 'resque', require: false
43
- gem 'shoryuken', require: false
44
- gem 'aws-sdk-sqs', require: false
45
- gem 'sidekiq', require: false
46
-
47
- gem 'kaminari', '~> 0.17.0', require: false
48
- gem 'will_paginate', require: false
49
-
50
- gem 'parallel', require: false
51
- end
52
-
53
- {'5.0' => '6.1', '5.1' => '6.3'}.each do |activesupport, mongoid|
54
- appraise "rails.#{activesupport}.mongoid.#{mongoid}" do
55
- gem 'mongoid', "~> #{mongoid}.0"
56
- gem 'activesupport', "~> #{activesupport}.0"
57
-
58
- gem 'activejob', "~> #{activesupport}.0"
59
- gem 'resque', require: false
60
- gem 'shoryuken', require: false
61
- gem 'aws-sdk-sqs', require: false
62
- gem 'sidekiq', require: false
63
-
64
- gem 'kaminari-core', '~> 1.1.0', require: false
65
- gem 'will_paginate', require: false
66
-
67
- gem 'parallel', require: false
68
- end
69
- end
70
-
71
- %w[4.45].each do |sequel|
72
- appraise "sequel.#{sequel}" do
73
- gem 'sequel', "~> #{sequel}.0"
74
- gem 'activesupport', '~> 5.1.0'
75
-
76
- gem 'kaminari-core', '~> 1.1.0', require: false
77
- gem 'will_paginate', require: false
78
-
79
- gem 'parallel', require: false
80
- end
81
- end
@@ -1,17 +0,0 @@
1
- # This file was generated by Appraisal
2
-
3
- source "https://rubygems.org"
4
-
5
- gem "mongoid", "~> 6.4.0"
6
- gem "activesupport", "~> 5.2.0"
7
- gem "activejob", "~> 5.2.0"
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
15
- gem 'rspec_junit_formatter', '~> 0.4.1'
16
-
17
- gemspec path: "../"
@@ -1,11 +0,0 @@
1
- # This file was generated by Appraisal
2
-
3
- source "https://rubygems.org"
4
-
5
- gem "sequel", "~> 4.45.0"
6
- gem "activesupport", "~> 5.1.0"
7
- gem "kaminari-core", "~> 1.1.0", require: false
8
- gem "will_paginate", require: false
9
- gem "parallel", require: false
10
-
11
- gemspec path: "../"
@@ -1,43 +0,0 @@
1
- module Chewy
2
- module Search
3
- module Pagination
4
- # This module provides `WillPaginate` support for {Chewy::Search::Request}
5
- # It is included automatically if `WillPaginate` is available.
6
- #
7
- # @example
8
- # PlacesIndex.all.paginate(page: 3, per_page: 10).order(:name)
9
- # # => <PlacesIndex::Query {..., :body=>{:size=>10, :from=>20, :sort=>["name"]}}>
10
- module WillPaginate
11
- extend ActiveSupport::Concern
12
-
13
- included do
14
- include ::WillPaginate::CollectionMethods
15
- attr_reader :current_page, :per_page
16
- end
17
-
18
- def paginate(options = {})
19
- @current_page = ::WillPaginate::PageNumber(options[:page] || @current_page || 1)
20
- @page_multiplier = @current_page - 1
21
- @per_page = (options[:per_page] || @per_page || ::WillPaginate.per_page).to_i
22
-
23
- # call Chewy::Search::Request methods to limit results
24
- limit(@per_page).offset(@page_multiplier * @per_page)
25
- end
26
-
27
- def page(page)
28
- paginate(page: page)
29
- end
30
-
31
- private
32
-
33
- def paginated_collection(collection)
34
- page = current_page || 1
35
- per = per_page || ::WillPaginate.per_page
36
- ::WillPaginate::Collection.create(page, per, total_entries) do |pager|
37
- pager.replace collection
38
- end
39
- end
40
- end
41
- end
42
- end
43
- end
@@ -1,27 +0,0 @@
1
- module Chewy
2
- class Strategy
3
- # The strategy works the same way as atomic, but performs
4
- # async index update driven by resque
5
- #
6
- # Chewy.strategy(:resque) do
7
- # User.all.map(&:save) # Does nothing here
8
- # Post.all.map(&:save) # And here
9
- # # It imports all the changed users and posts right here
10
- # end
11
- #
12
- class Resque < Atomic
13
- class Worker
14
- @queue = :chewy
15
-
16
- def self.perform(type, ids, options = {})
17
- options[:refresh] = !Chewy.disable_refresh_async if Chewy.disable_refresh_async
18
- type.constantize.import!(ids, options)
19
- end
20
- end
21
-
22
- def leave
23
- @stash.all? { |type, ids| ::Resque.enqueue(Chewy::Strategy::Resque::Worker, type.name, ids) }
24
- end
25
- end
26
- end
27
- end
@@ -1,40 +0,0 @@
1
- module Chewy
2
- class Strategy
3
- # The strategy works the same way as atomic, but performs
4
- # async index update driven by shoryuken
5
- #
6
- # Chewy.strategy(:shoryuken) do
7
- # User.all.map(&:save) # Does nothing here
8
- # Post.all.map(&:save) # And here
9
- # # It imports all the changed users and posts right here
10
- # end
11
- #
12
- class Shoryuken < Atomic
13
- class Worker
14
- include ::Shoryuken::Worker
15
-
16
- shoryuken_options auto_delete: true,
17
- body_parser: :json
18
-
19
- def perform(_sqs_msg, body)
20
- options = body['options'] || {}
21
- options[:refresh] = !Chewy.disable_refresh_async if Chewy.disable_refresh_async
22
- body['type'].constantize.import!(body['ids'], options.deep_symbolize_keys!)
23
- end
24
- end
25
-
26
- def leave
27
- @stash.each do |type, ids|
28
- next if ids.empty?
29
- Shoryuken::Worker.perform_async({type: type.name, ids: ids}, queue: shoryuken_queue)
30
- end
31
- end
32
-
33
- private
34
-
35
- def shoryuken_queue
36
- Chewy.settings.fetch(:shoryuken, {})[:queue] || 'chewy'
37
- end
38
- end
39
- end
40
- end
data/lib/chewy/type.rb DELETED
@@ -1,120 +0,0 @@
1
- require 'chewy/search'
2
- require 'chewy/type/adapter/object'
3
- require 'chewy/type/adapter/active_record'
4
- require 'chewy/type/adapter/mongoid'
5
- require 'chewy/type/adapter/sequel'
6
- require 'chewy/type/mapping'
7
- require 'chewy/type/wrapper'
8
- require 'chewy/type/observe'
9
- require 'chewy/type/actions'
10
- require 'chewy/type/syncer'
11
- require 'chewy/type/crutch'
12
- require 'chewy/type/import'
13
- require 'chewy/type/witchcraft'
14
-
15
- module Chewy
16
- class Type
17
- IMPORT_OPTIONS_KEYS = %i[
18
- batch_size bulk_size consistency direct_import journal
19
- pipeline raw_import refresh replication
20
- ].freeze
21
-
22
- include Search
23
- include Mapping
24
- include Wrapper
25
- include Observe
26
- include Actions
27
- include Crutch
28
- include Witchcraft
29
- include Import
30
-
31
- singleton_class.delegate :index_name, :derivable_index_name, :client, to: :index
32
-
33
- class_attribute :_default_import_options
34
- self._default_import_options = {}
35
-
36
- class << self
37
- # Chewy index current type belongs to. Defined inside `Chewy.create_type`
38
- #
39
- def index
40
- raise NotImplementedError, 'Looks like this type was defined outside the index scope and `.index` method is undefined for it'
41
- end
42
-
43
- # Current type adapter. Defined inside `Chewy.create_type`, derived from
44
- # `Chewy::Index.define_type` arguments.
45
- #
46
- def adapter
47
- raise NotImplementedError
48
- end
49
-
50
- # Returns type name string
51
- #
52
- def type_name
53
- adapter.type_name
54
- end
55
-
56
- # Appends type name to {Chewy::Index.derivable_name}
57
- #
58
- # @example
59
- # class Namespace::UsersIndex < Chewy::Index
60
- # define_type User
61
- # end
62
- # UsersIndex::User.derivable_name # => 'namespace/users#user'
63
- #
64
- # @see Chewy::Index.derivable_name
65
- # @return [String, nil] derivable name or nil when it is impossible to calculate
66
- def derivable_name
67
- @derivable_name ||= [index.derivable_name, type_name].join('#') if index && index.derivable_name
68
- end
69
-
70
- # This method is an API shared with {Chewy::Index}, added for convenience.
71
- #
72
- # @return [Chewy::Type] array containing itself
73
- def types
74
- [self]
75
- end
76
-
77
- # Returns list of public class methods defined in current type
78
- #
79
- def scopes
80
- public_methods - Chewy::Type.public_methods
81
- end
82
-
83
- def default_import_options(params)
84
- params.assert_valid_keys(IMPORT_OPTIONS_KEYS)
85
- self._default_import_options = _default_import_options.merge(params)
86
- end
87
-
88
- def method_missing(method, *args, &block)
89
- if index.scopes.include?(method)
90
- define_singleton_method method do |*method_args, &method_block|
91
- all.scoping { index.public_send(method, *method_args, &method_block) }
92
- end
93
- send(method, *args, &block)
94
- else
95
- super
96
- end
97
- end
98
-
99
- def respond_to_missing?(method, _)
100
- index.scopes.include?(method) || super
101
- end
102
-
103
- def const_missing(name)
104
- to_resolve = "#{self}::#{name}"
105
- to_resolve[index.to_s] = ''
106
-
107
- @__resolved_constants ||= {}
108
-
109
- if to_resolve.empty? || @__resolved_constants[to_resolve]
110
- super
111
- else
112
- @__resolved_constants[to_resolve] = true
113
- to_resolve.constantize
114
- end
115
- rescue NotImplementedError
116
- super
117
- end
118
- end
119
- end
120
- end