diff --git a/lib/whenever/cron.rb b/lib/whenever/cron.rb index a68b40b..95d74b5 100644 --- a/lib/whenever/cron.rb +++ b/lib/whenever/cron.rb @@ -1,6 +1,7 @@ module Whenever module Output class Cron + REGEX = /^.+ .+ .+ .+ .+.?$/ attr_accessor :time, :task @@ -10,9 +11,14 @@ module Whenever @at = at.is_a?(String) ? (Chronic.parse(at) || 0) : (at || 0) end - def self.enumerate(item) + def self.enumerate(item, detect_cron = true) if item and item.is_a?(String) - items = item.split(',') + items = + if detect_cron && item =~ REGEX + [item] + else + item.split(',') + end else items = item items = [items] unless items and items.respond_to?(:each) @@ -22,7 +28,7 @@ module Whenever def self.output(times, job) enumerate(times).each do |time| - enumerate(job.at).each do |at| + enumerate(job.at, false).each do |at| yield new(time, job.output, at).output end end @@ -34,7 +40,7 @@ module Whenever def time_in_cron_syntax case @time - when /^.+ .+ .+ .+ .+.?$/ then @time # raw cron sytax given + when REGEX then @time # raw cron sytax given when Symbol then parse_symbol when String then parse_as_string else parse_time diff --git a/test/functional/output_at_test.rb b/test/functional/output_at_test.rb index 2ee620d..e30431e 100644 --- a/test/functional/output_at_test.rb +++ b/test/functional/output_at_test.rb @@ -254,14 +254,14 @@ class OutputAtTest < Test::Unit::TestCase @output = Whenever.cron \ <<-file set :job_template, nil - every '0 0 27-31 * *' do + every '0 0 27,31 * *' do command "blahblah" end file end should "output the command using the same cron syntax" do - assert_match '0 0 27-31 * * blahblah', @output + assert_match '0 0 27,31 * * blahblah', @output end end