Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Sets the PATH automatically unless it's already provided or told not to.

  • Loading branch information...
commit 51a6b3720a37bb1412ae60efeba368c6f81e43e4 1 parent ed86aeb
@javan authored
View
7 CHANGELOG.rdoc
@@ -1,6 +1,11 @@
+== 0.3.6 / June 15th, 2009
+
+* Setting a PATH in the crontab automatically based on the user's PATH. [Javan Makhmali]
+
+
== 0.3.5 / June 13th, 2009
-* Added ability to accept lists of every's and at's and intelligently group them. (ex: every 'monday, wednesday', :at => ['3pm, 6am']). [Sam Ruby]
+* Added ability to accept lists of every's and at's and intelligently group them. (ex: every 'monday, wednesday', :at => ['3pm', '6am']). [Sam Ruby]
* Fixed issue with new lines. #18 [Javan Makhmali]
View
15 lib/job_list.rb
@@ -57,6 +57,8 @@ def rake(task, options = {})
end
def generate_cron_output
+ set_path_environment_variable
+
[environment_variables, cron_jobs].compact.join
end
@@ -77,6 +79,19 @@ def pre_set(variable_string = nil)
set(variable.strip, value.strip) unless variable.blank? || value.blank?
end
end
+
+ def set_path_environment_variable
+ return if path_should_not_be_set_automatically?
+ @env[:PATH] = read_path unless read_path.blank?
+ end
+
+ def read_path
+ ENV['PATH'] if ENV
+ end
+
+ def path_should_not_be_set_automatically?
+ @set_path_automatically === false || @env[:PATH] || @env["PATH"]
+ end
def environment_variables
return if @env.empty?
View
2  lib/version.rb
@@ -2,7 +2,7 @@ module Whenever
module VERSION #:nodoc:
MAJOR = 0
MINOR = 3
- TINY = 5
+ TINY = 6
STRING = [MAJOR, MINOR, TINY].join('.')
end
View
33 test/output_env_test.rb
@@ -19,5 +19,38 @@ class OutputEnvTest < Test::Unit::TestCase
assert_match "MAILTO=someone@example.com", @output
end
end
+
+ context "No PATH environment variable set" do
+ setup do
+ Whenever::JobList.any_instance.expects(:read_path).at_least_once.returns('/usr/local/bin')
+ @output = Whenever.cron ""
+ end
+
+ should "add a PATH variable based on the user's PATH" do
+ assert_match "PATH=/usr/local/bin", @output
+ end
+ end
+
+ context "A PATH environment variable set" do
+ setup do
+ Whenever::JobList.stubs(:read_path).returns('/usr/local/bin')
+ @output = Whenever.cron "env :PATH, '/my/path'"
+ end
+
+ should "use that path and the user's PATH" do
+ assert_match "PATH=/my/path", @output
+ assert_no_match /local/, @output
+ end
+ end
+
+ context "No PATH set and instructed not to automatically load the user's path" do
+ setup do
+ @output = Whenever.cron "set :set_path_automatically, false"
+ end
+
+ should "not have a PATH set" do
+ assert_no_match /PATH/, @output
+ end
+ end
end
View
4 whenever.gemspec
@@ -2,11 +2,11 @@
Gem::Specification.new do |s|
s.name = %q{whenever}
- s.version = "0.3.5"
+ s.version = "0.3.6"
s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
s.authors = ["Javan Makhmali"]
- s.date = %q{2009-07-13}
+ s.date = %q{2009-07-15}
s.description = %q{Provides clean ruby syntax for defining messy cron jobs and running them Whenever.}
s.email = %q{javan@javan.us}
s.executables = ["whenever", "wheneverize"]
Please sign in to comment.
Something went wrong with that request. Please try again.