Commit 7ad4cd0ba7b297349061b1fe9e5d99804713f6ac
1 parent
3ce4ba21
Exists in
master
and in
17 other branches
Cleaner rake task integration
Showing
4 changed files
with
35 additions
and
36 deletions
Show diff stats
lib/searchkick.rb
... | ... | @@ -17,15 +17,9 @@ require "searchkick/record_indexer" |
17 | 17 | require "searchkick/results" |
18 | 18 | require "searchkick/version" |
19 | 19 | |
20 | +require "searchkick/railtie" if defined?(Rails) | |
20 | 21 | require "searchkick/logging" if defined?(ActiveSupport::Notifications) |
21 | 22 | |
22 | -begin | |
23 | - require "rake" | |
24 | -rescue LoadError | |
25 | - # do nothing | |
26 | -end | |
27 | -require "searchkick/tasks" if defined?(Rake) | |
28 | - | |
29 | 23 | # background jobs |
30 | 24 | begin |
31 | 25 | require "active_job" | ... | ... |
lib/searchkick/tasks.rb
... | ... | @@ -1,29 +0,0 @@ |
1 | -namespace :searchkick do | |
2 | - desc "reindex model" | |
3 | - task reindex: :environment do | |
4 | - if ENV["CLASS"] | |
5 | - klass = ENV["CLASS"].constantize rescue nil | |
6 | - if klass | |
7 | - klass.reindex | |
8 | - else | |
9 | - abort "Could not find class: #{ENV['CLASS']}" | |
10 | - end | |
11 | - else | |
12 | - abort "USAGE: rake searchkick:reindex CLASS=Product" | |
13 | - end | |
14 | - end | |
15 | - | |
16 | - if defined?(Rails) | |
17 | - namespace :reindex do | |
18 | - desc "reindex all models" | |
19 | - task all: :environment do | |
20 | - Rails.application.eager_load! | |
21 | - Searchkick.models.each do |model| | |
22 | - puts "Reindexing #{model.name}..." | |
23 | - model.reindex | |
24 | - end | |
25 | - puts "Reindex complete" | |
26 | - end | |
27 | - end | |
28 | - end | |
29 | -end |
... | ... | @@ -0,0 +1,27 @@ |
1 | +namespace :searchkick do | |
2 | + desc "reindex model" | |
3 | + task reindex: :environment do | |
4 | + if ENV["CLASS"] | |
5 | + klass = ENV["CLASS"].constantize rescue nil | |
6 | + if klass | |
7 | + klass.reindex | |
8 | + else | |
9 | + abort "Could not find class: #{ENV['CLASS']}" | |
10 | + end | |
11 | + else | |
12 | + abort "USAGE: rake searchkick:reindex CLASS=Product" | |
13 | + end | |
14 | + end | |
15 | + | |
16 | + namespace :reindex do | |
17 | + desc "reindex all models" | |
18 | + task all: :environment do | |
19 | + Rails.application.eager_load! | |
20 | + Searchkick.models.each do |model| | |
21 | + puts "Reindexing #{model.name}..." | |
22 | + model.reindex | |
23 | + end | |
24 | + puts "Reindex complete" | |
25 | + end | |
26 | + end | |
27 | +end | ... | ... |