whenever 0.5.3 → 0.6.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,11 +1,29 @@
1
- == 0.5.3 / September 24th, 2010
1
+ ### 0.6.2 / October 26th, 2010
2
+
3
+ * --clear-crontab option completely removes entries. #63 [Javan Makhmali]
4
+
5
+ * Set default :environment and :path earlier in the new setup.rb (formerly job_types/default.rb). [Javan Makhmali]
6
+
7
+ * Converted README and CHANGELOG to markdown. [Javan Makhmali]
8
+
9
+
10
+ ### 0.6.1 / October 20th, 2010
11
+
12
+ * Detect script/rails file and change runner to Rails 3 style if found. [Javan Makhmali]
13
+
14
+ * Created a new :job_template system that can be applied to all commands. Wraps all in bash -l -c 'command..' by default now for better RVM support. Stopped automatically setting the PATH too. [Javan Makhmali]
15
+
16
+ * Added a built-in Capistrano recipe. [Javan Makhmali]
17
+
18
+
19
+ ### 0.5.3 / September 24th, 2010
2
20
 
3
21
  * Better regexes for replacing Whenever blocks in the crontab. #45 [Javan Makhmali]
4
22
 
5
23
  * Preserving backslashes when updating existing crontab. #82 [Javan Makhmali]
6
24
 
7
25
 
8
- == 0.5.2 / September 15th, 2010
26
+ ### 0.5.2 / September 15th, 2010
9
27
 
10
28
  * Quotes automatically escaped in jobs. [Jay Adkisson]
11
29
 
@@ -16,7 +34,7 @@
16
34
  * Lots of internal reorganizing; tests broken into unit and functional. [Javan Makhmali]
17
35
 
18
36
 
19
- == 0.5.0 / June 28th, 2010
37
+ ### 0.5.0 / June 28th, 2010
20
38
 
21
39
  * New job_type API for writing custom jobs. Internals use this to define command, runner, and rake. [Javan Makhmali - inspired by idlefingers (Damien)]
22
40
 
@@ -25,7 +43,7 @@
25
43
  * --clear option to remove crontab entries for a specific [identifier]. [mraidel (Michael Raidel)]
26
44
 
27
45
 
28
- == 0.4.2 / April 26th, 2010
46
+ ### 0.4.2 / April 26th, 2010
29
47
 
30
48
  * runners now cd into the app's directory and then execute. [Michael Guterl]
31
49
 
@@ -36,49 +54,49 @@
36
54
  * bugfix: comparison Time with 0 failed. #32 [Dan Hixon]
37
55
 
38
56
 
39
- == 0.4.1 / November 30th, 2009
57
+ ### 0.4.1 / November 30th, 2009
40
58
 
41
59
  * exit(0) instead of just exit to make JRuby happy. [Elan Meng]
42
60
 
43
61
  * Fixed activesupport deprecation warning by requiring active_support. #37 [Andrew Nesbitt]
44
62
 
45
63
 
46
- == 0.4.0 / October 20th, 2009
64
+ ### 0.4.0 / October 20th, 2009
47
65
 
48
66
  * New output option replaces the old cron_log option for output redirection and is much more flexible. #31 [Peer Allan]
49
67
 
50
68
  * Reorganized the lib files (http://weblog.rubyonrails.org/2009/9/1/gem-packaging-best-practices) and switched to Jeweler from Echoe.
51
69
 
52
70
 
53
- == 0.3.7 / September 4th, 2009
71
+ ### 0.3.7 / September 4th, 2009
54
72
 
55
73
  * No longer tries (and fails) to combine @shortcut jobs. #20 [Javan Makhmali]
56
74
 
57
75
 
58
- == 0.3.6 / June 15th, 2009
76
+ ### 0.3.6 / June 15th, 2009
59
77
 
60
78
  * Setting a PATH in the crontab automatically based on the user's PATH. [Javan Makhmali]
61
79
 
62
80
 
63
- == 0.3.5 / June 13th, 2009
81
+ ### 0.3.5 / June 13th, 2009
64
82
 
65
83
  * Added ability to accept lists of every's and at's and intelligently group them. (ex: every 'monday, wednesday', :at => ['3pm', '6am']). [Sam Ruby]
66
84
 
67
85
  * Fixed issue with new lines. #18 [Javan Makhmali]
68
86
 
69
- == 0.3.1 / June 25th, 2009
87
+ ### 0.3.1 / June 25th, 2009
70
88
 
71
89
  * Removed activesupport gem dependency. #1 [Javan Makhmali]
72
90
 
73
91
  * Switched to numeric days of the week for Solaris support (and probably others). #8 [Roger Ertesvåg]
74
92
 
75
93
 
76
- == 0.3.0 / June 2nd, 2009
94
+ ### 0.3.0 / June 2nd, 2009
77
95
 
78
96
  * Added ability to set variables on the fly from the command line (ex: whenever --set environment=staging). [Javan Makhmali]
79
97
 
80
98
 
81
- == 0.2.2 / April 30th, 2009
99
+ ### 0.2.2 / April 30th, 2009
82
100
 
83
101
  * Days of week jobs can now accept an :at directive (ex: every :monday, :at => '5pm'). [David Eisinger]
84
102
 
@@ -87,22 +105,22 @@
87
105
  * Raising an exception if someone tries to specify an :at with a cron shortcut (:day, :reboot, etc) so there are no false hopes. [Javan Makhmali]
88
106
 
89
107
 
90
- == 0.1.7 / March 5th, 2009
108
+ ### 0.1.7 / March 5th, 2009
91
109
 
92
110
  * Added ability to update the crontab file non-destuctively instead of only overwriting it. [Javan Makhmali -- Inspired by code submitted individually from: Tien Dung (tiendung), Tom Lea (cwninja), Kyle Maxwell (fizx), and Andrew Timberlake (andrewtimberlake) on github]
93
111
 
94
112
 
95
- == 0.1.5 / February 19th, 2009
113
+ ### 0.1.5 / February 19th, 2009
96
114
 
97
115
  * Fixed load path so Whenever's files don't conflict with anything in Rails. Thanks Ryan Koopmans. [Javan Makhmali]
98
116
 
99
117
 
100
- == 0.1.4 / February 17th, 2009
118
+ ### 0.1.4 / February 17th, 2009
101
119
 
102
120
  * Added --load-file and --user opts to whenever binary. [Javan Makhmali]
103
121
 
104
122
 
105
- == 0.1.3 / February 16th, 2009
123
+ ### 0.1.3 / February 16th, 2009
106
124
 
107
125
  * Added 'rake' helper for defining scheduled rake tasks. [Javan Makhmali]
108
126
 
@@ -115,6 +133,6 @@
115
133
  * Requiring specific gem versions: Chronic >=0.2.3 and activesupport >= 1.3.0 [Javan Makhmali]
116
134
 
117
135
 
118
- == 0.1.0 / February 15th, 2009
136
+ ### 0.1.0 / February 15th, 2009
119
137
 
120
138
  * Initial release [Javan Makhmali]
data/README.md ADDED
@@ -0,0 +1,139 @@
1
+ ### Introduction
2
+
3
+ Whenever is a Ruby gem that provides a clear syntax for writing and deploying cron jobs.
4
+
5
+ ### Installation
6
+
7
+ $ gem install whenever
8
+
9
+ Or with Bundler in your Gemfile.
10
+
11
+ gem 'whenever', :require => false
12
+
13
+ ### Getting started
14
+
15
+ $ cd /my/rails/app
16
+ $ wheneverize .
17
+
18
+ This will create an initial "config/schedule.rb" file you.
19
+
20
+ ### Example schedule.rb file
21
+
22
+ every 3.hours do
23
+ runner "MyModel.some_process"
24
+ rake "my:rake:task"
25
+ command "/usr/bin/my_great_command"
26
+ end
27
+
28
+ every 1.day, :at => '4:30 am' do
29
+ runner "MyModel.task_to_run_at_four_thirty_in_the_morning"
30
+ end
31
+
32
+ every :hour do # Many shortcuts available: :hour, :day, :month, :year, :reboot
33
+ runner "SomeModel.ladeeda"
34
+ end
35
+
36
+ every :sunday, :at => '12pm' do # Use any day of the week or :weekend, :weekday
37
+ runner "Task.do_something_great"
38
+ end
39
+
40
+ More examples on the wiki: <http://wiki.github.com/javan/whenever/instructions-and-examples>
41
+
42
+ ### Define your own job types
43
+
44
+ Whenever ships with three pre-defined job types: command, runner, and rake. You can define your own with `job_type`.
45
+
46
+ For example:
47
+
48
+ job_type :awesome, '/usr/local/bin/awesome :task :fun_level'
49
+
50
+ every 2.hours do
51
+ awesome "party", :fun_level => "extreme"
52
+ end
53
+
54
+ Would run `/usr/local/bin/awesome party extreme` every two hours. `:task` is always replaced with the first argument, and any additional `:whatevers` are replaced with the options passed in or by variables that have been defined with `set`.
55
+
56
+ The default job types that ship with Whenever are defined like so:
57
+
58
+ job_type :command, ":task :output"
59
+ job_type :rake, "cd :path && RAILS_ENV=:environment rake :task :output"
60
+ job_type :runner, "cd :path && script/runner -e :environment ':task' :output"
61
+
62
+ If a script/rails file is detected (like in a Rails 3 app), runner will be defined to fit:
63
+
64
+ job_type :runner, "cd :path && script/rails runner -e :environment ':task' :output"
65
+
66
+ If a `:path` is not set it will default to the directory in which `whenever` was executed. `:environment` will default to 'production'. `:output` will be replaced with your output redirection settings which you can read more about here: <http://github.com/javan/whenever/wiki/Output-redirection-aka-logging-your-cron-jobs>
67
+
68
+ All jobs are by default run with `bash -l -c 'command...'`. Among other things, this allows your cron jobs to play nice with RVM by loading the entire environment instead of cron's somewhat limited environment. Read more: <http://blog.scoutapp.com/articles/2010/09/07/rvm-and-cron-in-production>
69
+
70
+ You can change this by setting your own `:job_template`.
71
+
72
+ set :job_template, "bash -l -c ':job'"
73
+
74
+ Or set the job_template to nil to have your jobs execute normally.
75
+
76
+ set :job_template, nil
77
+
78
+ And you'll see your schedule.rb converted to cron sytax. Note: running `whenever` with no options does not display your current crontab file, it simply shows you the output of converting your schedule.rb file.
79
+
80
+ ### Capistrano integration
81
+
82
+ Use the built-in Capistrano recipe for easy crontab updates with deploys.
83
+
84
+ In your "config/deploy.rb" file:
85
+
86
+ require "whenever/capistrano"
87
+
88
+ Take a look at the recipe for options you can set. <http://github.com/javan/whenever/blob/master/lib/whenever/capistrano.rb>
89
+ For example, if you're using bundler do this:
90
+
91
+ set :whenever_command, "bundle exec whenever"
92
+ require "whenever/capistrano"
93
+
94
+ ### The `whenever` command
95
+
96
+ $ cd /my/rails/app
97
+ $ whenever
98
+
99
+ This will simply show you your schedule.rb file converted to cron syntax. It does not read or write your crontab file. Run `whenever --help` for a complete list of options.
100
+
101
+ ### Credit
102
+
103
+ Whenever was created for use at Inkling (<http://inklingmarkets.com>) where I work. Their take on it: <http://blog.inklingmarkets.com/2009/02/whenever-easy-way-to-do-cron-jobs-from.html>
104
+
105
+ Thanks to all the contributors who have made it even better: <http://github.com/javan/whenever/contributors>
106
+
107
+ ### Discussion / Feedback / Issues / Bugs
108
+
109
+ For general discussion and questions, please use the google group: <http://groups.google.com/group/whenever-gem>
110
+
111
+ If you've found a genuine bug or issue, please use the Issues section on github: <http://github.com/javan/whenever/issues>
112
+
113
+ Ryan Bates created a great Railscast about Whenever: <http://railscasts.com/episodes/164-cron-in-ruby>
114
+ It's a little bit dated now, but remains a good introduction.
115
+
116
+ ### License
117
+
118
+ Copyright (c) 2009+ Javan Makhmali
119
+
120
+ Permission is hereby granted, free of charge, to any person
121
+ obtaining a copy of this software and associated documentation
122
+ files (the "Software"), to deal in the Software without
123
+ restriction, including without limitation the rights to use,
124
+ copy, modify, merge, publish, distribute, sublicense, and/or sell
125
+ copies of the Software, and to permit persons to whom the
126
+ Software is furnished to do so, subject to the following
127
+ conditions:
128
+
129
+ The above copyright notice and this permission notice shall be
130
+ included in all copies or substantial portions of the Software.
131
+
132
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
133
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
134
+ OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
135
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
136
+ HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
137
+ WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
138
+ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
139
+ OTHER DEALINGS IN THE SOFTWARE.
data/Rakefile CHANGED
@@ -8,8 +8,8 @@ begin
8
8
  Jeweler::Tasks.new do |gemspec|
9
9
  gemspec.name = "whenever"
10
10
  gemspec.version = Whenever::VERSION
11
- gemspec.summary = "Clean ruby syntax for defining and deploying messy cron jobs."
12
- gemspec.description = "Clean ruby syntax for defining and deploying messy cron jobs."
11
+ gemspec.summary = "Write your cron jobs in ruby."
12
+ gemspec.description = "Clean ruby syntax for writing and deploying cron jobs."
13
13
  gemspec.email = "javan@javan.us"
14
14
  gemspec.homepage = "http://github.com/javan/whenever"
15
15
  gemspec.authors = ["Javan Makhmali"]
data/bin/whenever CHANGED
@@ -4,32 +4,35 @@ require 'rubygems'
4
4
  require 'optparse'
5
5
  require 'whenever'
6
6
 
7
- options = Hash.new
7
+ options = {}
8
8
 
9
9
  OptionParser.new do |opts|
10
10
  opts.banner = "Usage: whenever [options]"
11
- opts.on('-v', '--version') { puts "Whenever v#{Whenever::VERSION}"; exit(0) }
12
- opts.on('-w', '--write-crontab') { options[:write] = true }
13
- opts.on('-c', '--cut [lines]', 'Cut lines from the top of the cronfile') do |lines|
14
- options[:cut] = lines.to_i if lines
15
- end
16
11
  opts.on('-i', '--update-crontab [identifier]', 'Default: full path to schedule.rb file') do |identifier|
17
12
  options[:update] = true
18
13
  options[:identifier] = identifier if identifier
19
14
  end
15
+ opts.on('-w', '--write-crontab [identifier]', 'Default: full path to schedule.rb file') do |identifier|
16
+ options[:write] = true
17
+ options[:identifier] = identifier if identifier
18
+ end
20
19
  opts.on('-c', '--clear-crontab [identifier]') do |identifier|
21
20
  options[:clear] = true
22
21
  options[:identifier] = identifier if identifier
23
22
  end
23
+ opts.on('-s', '--set [variables]', 'Example: --set environment=staging&path=/my/sweet/path') do |set|
24
+ options[:set] = set if set
25
+ end
24
26
  opts.on('-f', '--load-file [schedule file]', 'Default: config/schedule.rb') do |file|
25
27
  options[:file] = file if file
26
28
  end
27
29
  opts.on('-u', '--user [user]', 'Default: current user') do |user|
28
30
  options[:user] = user if user
29
31
  end
30
- opts.on('-s', '--set [variables]', 'Example: --set environment=staging&path=/my/sweet/path') do |set|
31
- options[:set] = set if set
32
+ opts.on('-k', '--cut [lines]', 'Cut lines from the top of the cronfile') do |lines|
33
+ options[:cut] = lines.to_i if lines
32
34
  end
35
+ opts.on('-v', '--version') { puts "Whenever v#{Whenever::VERSION}"; exit(0) }
33
36
  end.parse!
34
37
 
35
38
  Whenever::CommandLine.execute(options)
@@ -0,0 +1,31 @@
1
+ Capistrano::Configuration.instance(:must_exist).load do
2
+
3
+ _cset(:whenever_roles) { :db }
4
+ _cset(:whenever_command) { "whenever" }
5
+ _cset(:whenever_identifier) { application }
6
+ _cset(:whenever_update_flags) { "--update-crontab #{whenever_identifier}" }
7
+ _cset(:whenever_clear_flags) { "--clear-crontab #{whenever_identifier}" }
8
+
9
+ # Disable cron jobs at the begining of a deploy.
10
+ after "deploy:update_code", "whenever:clear_crontab"
11
+ # Write the new cron jobs near the end.
12
+ after "deploy:symlink", "whenever:update_crontab"
13
+ # If anything goes wrong, undo.
14
+ after "deploy:rollback", "whenever:update_crontab"
15
+
16
+ namespace :whenever do
17
+ desc "Update application's crontab entries using Whenever"
18
+ task :update_crontab, :roles => whenever_roles do
19
+ # Hack by Jamis to skip a task if the role has no servers defined. http://tinyurl.com/ckjgnz
20
+ next if find_servers_for_task(current_task).empty?
21
+ run "cd #{current_path} && #{whenever_command} #{whenever_update_flags}"
22
+ end
23
+
24
+ desc "Clear application's crontab entries using Whenever"
25
+ task :clear_crontab, :roles => whenever_roles do
26
+ next if find_servers_for_task(current_task).empty?
27
+ run "cd #{release_path} && #{whenever_command} #{whenever_clear_flags}"
28
+ end
29
+ end
30
+
31
+ end
@@ -30,7 +30,6 @@ module Whenever
30
30
  exit(1)
31
31
  end
32
32
  @options[:cut] = @options[:cut].to_i
33
-
34
33
  end
35
34
 
36
35
  def run
@@ -51,7 +50,8 @@ module Whenever
51
50
  end
52
51
 
53
52
  def whenever_cron
54
- @whenever_cron ||= [comment_open, (Whenever.cron(@options) unless @options[:clear]), comment_close].compact.join("\n") + "\n"
53
+ return '' if @options[:clear]
54
+ @whenever_cron ||= [comment_open, Whenever.cron(@options), comment_close].compact.join("\n") + "\n"
55
55
  end
56
56
 
57
57
  def read_crontab
@@ -102,7 +102,7 @@ module Whenever
102
102
  read_crontab.gsub(Regexp.new("^#{comment_open}$.+^#{comment_close}$", Regexp::MULTILINE), whenever_cron.chomp.gsub('\\', '\\\\\\'))
103
103
  else # Otherwise, append the new cron entries after any existing ones
104
104
  [read_crontab, whenever_cron].join("\n\n")
105
- end
105
+ end.gsub(/\n{3,}/, "\n\n") # More than two newlines becomes just two.
106
106
  end
107
107
 
108
108
  def prepare(contents)
data/lib/whenever/cron.rb CHANGED
@@ -4,11 +4,10 @@ module Whenever
4
4
 
5
5
  attr_accessor :time, :task
6
6
 
7
- def initialize(time = nil, task = nil, at = nil, output_redirection = nil)
7
+ def initialize(time = nil, task = nil, at = nil)
8
8
  @time = time
9
9
  @task = task
10
10
  @at = at.is_a?(String) ? (Chronic.parse(at) || 0) : (at || 0)
11
- @output_redirection = output_redirection
12
11
  end
13
12
 
14
13
  def self.enumerate(item)
@@ -24,13 +23,13 @@ module Whenever
24
23
  def self.output(times, job)
25
24
  enumerate(times).each do |time|
26
25
  enumerate(job.at).each do |at|
27
- yield new(time, job.output, at, job.output_redirection).output
26
+ yield new(time, job.output, at).output
28
27
  end
29
28
  end
30
29
  end
31
30
 
32
31
  def output
33
- [time_in_cron_syntax, task, output_redirection].compact.join(' ').strip
32
+ [time_in_cron_syntax, task].compact.join(' ').strip
34
33
  end
35
34
 
36
35
  def time_in_cron_syntax
@@ -40,10 +39,6 @@ module Whenever
40
39
  else parse_time
41
40
  end
42
41
  end
43
-
44
- def output_redirection
45
- Whenever::Output::Cron::OutputRedirection.new(@output_redirection).to_s unless @output_redirection == :not_set
46
- end
47
42
 
48
43
  protected
49
44
 
data/lib/whenever/job.rb CHANGED
@@ -1,21 +1,29 @@
1
1
  module Whenever
2
2
  class Job
3
3
 
4
- attr_reader :at, :output_redirection
4
+ attr_reader :at
5
5
 
6
6
  def initialize(options = {})
7
7
  @options = options
8
-
9
- @at = options[:at]
10
- @output_redirection = options.has_key?(:output) ? options[:output] : :not_set
8
+ @at = options.delete(:at)
9
+ @template = options.delete(:template)
10
+ @job_template = options.delete(:job_template) || ":job"
11
+ @options[:output] = Whenever::Output::Redirection.new(options[:output]).to_s if options.has_key?(:output)
11
12
  @options[:environment] ||= :production
12
13
  @options[:path] ||= Whenever.path
13
14
  end
14
15
 
15
16
  def output
16
- @options[:template].dup.gsub(/:\w+/) do |key|
17
+ job = process_template(@template, @options).strip
18
+ process_template(@job_template, { :job => job }).strip
19
+ end
20
+
21
+ protected
22
+
23
+ def process_template(template, options)
24
+ template.gsub(/:\w+/) do |key|
17
25
  before_and_after = [$`[-1..-1], $'[0..0]]
18
- option = @options[key.sub(':', '').to_sym]
26
+ option = options[key.sub(':', '').to_sym]
19
27
 
20
28
  if before_and_after.all? { |c| c == "'" }
21
29
  escape_single_quotes(option)
@@ -26,8 +34,6 @@ module Whenever
26
34
  end
27
35
  end
28
36
  end
29
-
30
- protected
31
37
 
32
38
  def escape_single_quotes(str)
33
39
  str.gsub(/'/) { "'\\''" }
@@ -2,7 +2,7 @@ module Whenever
2
2
  class JobList
3
3
 
4
4
  def initialize(options)
5
- @jobs, @env, @set_variables = {}, {}, {}
5
+ @jobs, @env, @set_variables, @pre_set_variables = {}, {}, {}, {}
6
6
 
7
7
  case options
8
8
  when String
@@ -16,16 +16,14 @@ module Whenever
16
16
  pre_set(options[:set])
17
17
  end
18
18
 
19
- # Load all job type files.
20
- Dir["#{File.expand_path(File.dirname(__FILE__))}/job_types/*.rb"].each do |file|
21
- eval(File.read(file))
22
- end
19
+ setup = File.read("#{File.expand_path(File.dirname(__FILE__))}/setup.rb")
23
20
 
24
- eval(config)
21
+ eval(setup + config)
25
22
  end
26
23
 
27
24
  def set(variable, value)
28
- return if instance_variable_defined?("@#{variable}".to_sym)
25
+ variable = variable.to_sym
26
+ return if @pre_set_variables[variable]
29
27
 
30
28
  instance_variable_set("@#{variable}".to_sym, value)
31
29
  self.class.send(:attr_reader, variable.to_sym)
@@ -59,9 +57,7 @@ module Whenever
59
57
  end
60
58
  end
61
59
 
62
- def generate_cron_output
63
- set_path_environment_variable
64
-
60
+ def generate_cron_output
65
61
  [environment_variables, cron_jobs].compact.join
66
62
  end
67
63
 
@@ -79,22 +75,13 @@ module Whenever
79
75
  pairs.each do |pair|
80
76
  next unless pair.index('=')
81
77
  variable, value = *pair.split('=')
82
- set(variable.strip.to_sym, value.strip) unless variable.blank? || value.blank?
78
+ unless variable.blank? || value.blank?
79
+ variable = variable.strip.to_sym
80
+ set(variable, value.strip)
81
+ @pre_set_variables[variable] = value
82
+ end
83
83
  end
84
84
  end
85
-
86
- def set_path_environment_variable
87
- return if path_should_not_be_set_automatically?
88
- @env[:PATH] = read_path unless read_path.blank?
89
- end
90
-
91
- def read_path
92
- ENV['PATH'] if ENV
93
- end
94
-
95
- def path_should_not_be_set_automatically?
96
- @set_path_automatically === false || @env[:PATH] || @env["PATH"]
97
- end
98
85
 
99
86
  def environment_variables
100
87
  return if @env.empty?
@@ -1,60 +1,58 @@
1
1
  module Whenever
2
2
  module Output
3
- class Cron
4
- class OutputRedirection
5
-
6
- def initialize(output)
7
- @output = output
8
- end
9
-
10
- def to_s
11
- return '' unless defined?(@output)
12
- case @output
13
- when String then redirect_from_string
14
- when Hash then redirect_from_hash
15
- when NilClass then ">> /dev/null 2>&1"
16
- else ''
17
- end
18
- end
19
-
20
- protected
21
-
22
- def stdout
23
- return unless @output.has_key?(:standard)
24
- @output[:standard].nil? ? '/dev/null' : @output[:standard]
25
- end
3
+ class Redirection
4
+
5
+ def initialize(output)
6
+ @output = output
7
+ end
8
+
9
+ def to_s
10
+ return '' unless defined?(@output)
11
+ case @output
12
+ when String then redirect_from_string
13
+ when Hash then redirect_from_hash
14
+ when NilClass then ">> /dev/null 2>&1"
15
+ else ''
16
+ end
17
+ end
18
+
19
+ protected
20
+
21
+ def stdout
22
+ return unless @output.has_key?(:standard)
23
+ @output[:standard].nil? ? '/dev/null' : @output[:standard]
24
+ end
26
25
 
27
- def stderr
28
- return unless @output.has_key?(:error)
29
- @output[:error].nil? ? '/dev/null' : @output[:error]
30
- end
26
+ def stderr
27
+ return unless @output.has_key?(:error)
28
+ @output[:error].nil? ? '/dev/null' : @output[:error]
29
+ end
31
30
 
32
- def redirect_from_hash
33
- case
34
- when stdout == '/dev/null' && stderr == '/dev/null'
35
- "> /dev/null 2>&1"
36
- when stdout && stderr == '/dev/null'
37
- ">> #{stdout} 2> /dev/null"
38
- when stdout && stderr
39
- ">> #{stdout} 2>> #{stderr}"
40
- when stderr == '/dev/null'
41
- "2> /dev/null"
42
- when stderr
43
- "2>> #{stderr}"
44
- when stdout == '/dev/null'
45
- "> /dev/null"
46
- when stdout
47
- ">> #{stdout}"
48
- else
49
- ''
50
- end
31
+ def redirect_from_hash
32
+ case
33
+ when stdout == '/dev/null' && stderr == '/dev/null'
34
+ "> /dev/null 2>&1"
35
+ when stdout && stderr == '/dev/null'
36
+ ">> #{stdout} 2> /dev/null"
37
+ when stdout && stderr
38
+ ">> #{stdout} 2>> #{stderr}"
39
+ when stderr == '/dev/null'
40
+ "2> /dev/null"
41
+ when stderr
42
+ "2>> #{stderr}"
43
+ when stdout == '/dev/null'
44
+ "> /dev/null"
45
+ when stdout
46
+ ">> #{stdout}"
47
+ else
48
+ ''
51
49
  end
50
+ end
52
51
 
53
- def redirect_from_string
54
- ">> #{@output} 2>&1"
55
- end
56
-
52
+ def redirect_from_string
53
+ ">> #{@output} 2>&1"
57
54
  end
55
+
58
56
  end
59
57
  end
60
58
  end