Commit 0e7bcb088ee44ff55bf22e87a9dc8b406cf968f8
1 parent
6e9e06f5
Exists in
master
and in
5 other branches
Improved output for reindex rake task
Showing
2 changed files
with
12 additions
and
11 deletions
Show diff stats
CHANGELOG.md
lib/tasks/searchkick.rake
1 | 1 | namespace :searchkick do |
2 | - desc "reindex model" | |
2 | + desc "reindex a model" | |
3 | 3 | task reindex: :environment do |
4 | - if ENV["CLASS"] | |
5 | - klass = ENV["CLASS"].safe_constantize | |
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 | |
4 | + class_name = ENV["CLASS"] | |
5 | + abort "USAGE: rake searchkick:reindex CLASS=Product" unless class_name | |
6 | + | |
7 | + model = class_name.safe_constantize | |
8 | + abort "Could not find class: #{class_name}" unless model | |
9 | + abort "#{class_name} is not a searchkick model" unless Searchkick.models.include?(model) | |
10 | + | |
11 | + puts "Reindexing #{model.name}..." | |
12 | + model.reindex | |
13 | + puts "Reindex successful" | |
14 | 14 | end |
15 | 15 | |
16 | 16 | namespace :reindex do | ... | ... |