Permalink
Browse files

Use rake task arguments for multisearch rebuild

The previous implementation required setting an
environment variable, which was not
self-documenting when running `rake -T`.
  • Loading branch information...
nertzy committed May 13, 2012
1 parent 7cdbced commit 27d7afa5f499fea2f1cfbd258356ddcf8cdccc67
Showing with 8 additions and 5 deletions.
  1. +1 −1 README.rdoc
  2. +7 −4 lib/pg_search/tasks.rb
View
@@ -120,7 +120,7 @@ To remove all of the documents for a given class, you can simply delete all of t
Run this Rake task to regenerate all of the documents for a given class.
- $ rake pg_search:multisearch:rebuild MODEL=BlogPost
+ $ rake pg_search:multisearch:rebuild[BlogPost]
Currently this is only supported for :against methods that directly map to Active Record attributes. Until that is fixed, you could also manually rebuild all of the documents.
View
@@ -3,10 +3,13 @@
namespace :pg_search do
namespace :multisearch do
- desc "Rebuild PgSearch multisearch records for MODEL"
- task :rebuild => :environment do
- raise "must set MODEL=<model name>" unless ENV["MODEL"]
- model_class = ENV["MODEL"].classify.constantize
+ desc "Rebuild PgSearch multisearch records for a given model"
+ task :rebuild, [:model] => :environment do |task, args|
+ raise ArgumentError, <<-MESSAGE unless args.model
+You must pass a model as an argument.
+Example: rake pg_search:multisearch:rebuild[BlogPost]
+ MESSAGE
+ model_class = args.model.classify.constantize
PgSearch::Multisearch.rebuild(model_class)
end
end

0 comments on commit 27d7afa

Please sign in to comment.