From a5bc0c8c32db054f814c324a12c0aab37c9fd183 Mon Sep 17 00:00:00 2001 From: Ken MacInnis Date: Mon, 10 Jun 2013 17:05:43 -0700 Subject: [PATCH] add load_environment option for rake to load the environment --- README.markdown | 1 + lib/guard/resque.rb | 5 ++++- lib/guard/resque/templates/Guardfile | 1 + spec/guard/resque_spec.rb | 5 +++++ 4 files changed, 11 insertions(+), 1 deletion(-) diff --git a/README.markdown b/README.markdown index 5eaf58f..ec8f05f 100644 --- a/README.markdown +++ b/README.markdown @@ -49,6 +49,7 @@ You can customize the resque task via the following options: * `verbose`: whether to use verbose logging (defaults to `nil`) * `vverbose`: whether to use very verbose logging (defaults to `nil`) * `trace`: whether to include `--trace` on the rake command (defaults to `nil`) +* `load_environment`: whether to include 'environment' on the rake command (defaults to `nil`) * `stop_signal`: how to kill the process when restarting (defaults to `QUIT`) diff --git a/lib/guard/resque.rb b/lib/guard/resque.rb index a9c8907..58ef82d 100644 --- a/lib/guard/resque.rb +++ b/lib/guard/resque.rb @@ -21,6 +21,7 @@ class Resque < Guard # - :vverbose e.g. true # - :trace e.g. true # - :stop_signal e.g. :QUIT or :SIGQUIT + # - :load_environment e.g. false def initialize(watchers = [], options = {}) @options = options @pid = nil @@ -85,7 +86,9 @@ def restart private def cmd - command = ['bundle exec rake', @options[:task].to_s] + command = ['bundle exec rake'] + command << 'environment' if @options[:load_environment] + command << @options[:task].to_s # trace setting command << '--trace' if @options[:trace] diff --git a/lib/guard/resque/templates/Guardfile b/lib/guard/resque/templates/Guardfile index 893e517..0cde18d 100644 --- a/lib/guard/resque/templates/Guardfile +++ b/lib/guard/resque/templates/Guardfile @@ -3,6 +3,7 @@ # - :task (defaults to 'resque:work' if :count is 1; 'resque:workers', otherwise) # - :verbose / :vverbose (set them to anything but false to activate their respective modes) # - :trace +# - :load_environment # - :queue (defaults to "*") # - :count (defaults to 1) # - :environment (corresponds to RAILS_ENV for the Resque worker) diff --git a/spec/guard/resque_spec.rb b/spec/guard/resque_spec.rb index 3237e4f..24ae2ff 100644 --- a/spec/guard/resque_spec.rb +++ b/spec/guard/resque_spec.rb @@ -39,6 +39,11 @@ obj.send(:cmd).should include '--trace' end + it 'should accept :load_environment option' do + obj = Guard::Resque.new [], :load_environment => true + obj.send(:cmd).should include 'environment' + end + it 'should accept :task option' do task = 'environment foo'