Skip to content

Commit

Permalink
Cleaner rake task integration
Browse files Browse the repository at this point in the history
  • Loading branch information
ankane committed Oct 22, 2018
1 parent 3ce4ba2 commit 7ad4cd0
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 17 deletions.
8 changes: 1 addition & 7 deletions lib/searchkick.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,9 @@
require "searchkick/results"
require "searchkick/version"

require "searchkick/railtie" if defined?(Rails)
require "searchkick/logging" if defined?(ActiveSupport::Notifications)

begin
require "rake"
rescue LoadError
# do nothing
end
require "searchkick/tasks" if defined?(Rake)

# background jobs
begin
require "active_job"
Expand Down
7 changes: 7 additions & 0 deletions lib/searchkick/railtie.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module Searckick
class Railtie < Rails::Railtie
rake_tasks do
load "tasks/searchkick.rake"
end
end
end
18 changes: 8 additions & 10 deletions lib/searchkick/tasks.rb → lib/tasks/searchkick.rake
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,15 @@
end
end

if defined?(Rails)
namespace :reindex do
desc "reindex all models"
task all: :environment do
Rails.application.eager_load!
Searchkick.models.each do |model|
puts "Reindexing #{model.name}..."
model.reindex
end
puts "Reindex complete"
namespace :reindex do
desc "reindex all models"
task all: :environment do
Rails.application.eager_load!
Searchkick.models.each do |model|
puts "Reindexing #{model.name}..."
model.reindex
end
puts "Reindex complete"
end
end
end

0 comments on commit 7ad4cd0

Please sign in to comment.