Skip to content

Commit

Permalink
Merge pull request sunspot#102 from sunspot/nz-move-rake-solr-tasks-t…
Browse files Browse the repository at this point in the history
…o-sunspot-solr

Move the sunspot:solr rake tasks to the sunspot_solr gem.
  • Loading branch information
alindeman committed Oct 10, 2011
2 parents 8187c8b + 35d9047 commit 3a40703
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 39 deletions.
64 changes: 26 additions & 38 deletions sunspot_rails/lib/sunspot/rails/tasks.rb
Original file line number Diff line number Diff line change
@@ -1,42 +1,4 @@
namespace :sunspot do
namespace :solr do
desc 'Start the Solr instance'
task :start => :environment do
if RUBY_PLATFORM =~ /w(in)?32$/
abort('This command does not work on Windows. Please use rake sunspot:solr:run to run Solr in the foreground.')
end

if defined?(Sunspot::Rails::Server)
Sunspot::Rails::Server.new.start
else
abort('sunspot_solr gem required for this command. Add gem "sunspot_solr" to Gemfile')
end
end

desc 'Run the Solr instance in the foreground'
task :run => :environment do
if defined?(Sunspot::Rails::Server)
Sunspot::Rails::Server.new.run
else
abort('sunspot_solr gem required for this command. Add gem "sunspot_solr" to Gemfile')
end
end

desc 'Stop the Solr instance'
task :stop => :environment do
if RUBY_PLATFORM =~ /w(in)?32$/
abort('This command does not work on Windows.')
end

if defined?(Sunspot::Rails::Server)
Sunspot::Rails::Server.new.stop
else
abort('sunspot_solr gem required for this command. Add gem "sunspot_solr" to Gemfile')
end
end

task :reindex => :"sunspot:reindex"
end

desc "Reindex all solr models that are located in your application's models directory."
# This task depends on the standard Rails file naming \
Expand Down Expand Up @@ -92,5 +54,31 @@
model.solr_reindex(reindex_options)
end
end


unless defined?(Sunspot::Solr)
namespace :solr do
task :moved_to_sunspot_solr do
abort %(
Note: This task has been moved to the sunspot_solr gem. To install, start and
stop a local Solr instance, please add sunspot_solr to your Gemfile:
group :development do
gem 'sunspot_solr'
end
)
end

desc 'Start the Solr instance'
task :start => :moved_to_sunspot_solr
desc 'Run the Solr instance in the foreground'
task :run => :moved_to_sunspot_solr
desc 'Stop the Solr instance'
task :stop => :moved_to_sunspot_solr
# for backwards compatibility
task :reindex => :"sunspot:reindex"
end
end

end
15 changes: 15 additions & 0 deletions sunspot_solr/lib/sunspot/solr/railtie.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
module Sunspot
module Solr
class Railtie < ::Rails::Railtie

rake_tasks do
load 'sunspot/solr/tasks.rb'
end

# generators do
# load "generators/sunspot_rails.rb"
# end

end
end
end
32 changes: 32 additions & 0 deletions sunspot_solr/lib/sunspot/solr/tasks.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
namespace :sunspot do
namespace :solr do

desc 'Start the Solr instance'
task :start => :environment do
case RUBY_PLATFORM
when /w(in)?32$/, /java$/
abort("This command is not supported on #{RUBY_PLATFORM}. " +
"Use rake sunspot:solr:run to run Solr in the foreground.")
end
Sunspot::Rails::Server.new.start
end

desc 'Run the Solr instance in the foreground'
task :run => :environment do
Sunspot::Rails::Server.new.run
end

desc 'Stop the Solr instance'
task :stop => :environment do
case RUBY_PLATFORM
when /w(in)?32$/, /java$/
abort("This command is not supported on #{RUBY_PLATFORM}. " +
"Use rake sunspot:solr:run to run Solr in the foreground.")
end
Sunspot::Rails::Server.new.stop
end

# for backwards compatibility
task :reindex => :"sunspot:reindex"
end
end
6 changes: 5 additions & 1 deletion sunspot_solr/lib/sunspot_solr.rb
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
require 'sunspot/solr/server'
require 'sunspot/solr/server'

if defined?(Rails) && Rails::VERSION::MAJOR == 3
require 'sunspot/solr/railtie'
end

0 comments on commit 3a40703

Please sign in to comment.