Permalink
Browse files

support all @ keywords in raw cron syntax

  • Loading branch information...
1 parent e6ecfc9 commit a1aa561bdd0d1a040dff74b873920c6f4aff3bbc @felixbuenemann felixbuenemann committed Dec 22, 2011
Showing with 4 additions and 10 deletions.
  1. +4 −10 lib/whenever/cron.rb
View
@@ -3,7 +3,8 @@
module Whenever
module Output
class Cron
- REGEX = /^.+ .+ .+ .+ .+.?$/
+ KEYWORDS = [:reboot, :yearly, :annually, :monthly, :weekly, :daily, :midnight, :hourly]
+ REGEX = /^(@(#{KEYWORDS.join '|'})|.+ .+ .+ .+ .+.?)$/
attr_accessor :time, :task
@@ -52,25 +53,18 @@ def time_in_cron_syntax
protected
def day_given?
- months = ["jan", "feb", "mar", "apr", "may", "jun", "jul", "aug", "sep", "oct", "nov", "dec"]
+ months = %w(jan feb mar apr may jun jul aug sep oct nov dec)
@at_given.is_a?(String) && months.any? { |m| @at_given.downcase.index(m) }
end
def parse_symbol
shortcut = case @time
- when :reboot then '@reboot'
+ when *KEYWORDS then "@#{@time}" # :reboot => '@reboot'
when :year then 12.months
- when :yearly,
- :annually then '@annually'
when :day then 1.day
- when :daily then '@daily'
- when :midnight then '@midnight'
when :month then 1.month
- when :monthly then '@monthly'
when :week then 1.week
- when :weekly then '@weekly'
when :hour then 1.hour
- when :hourly then '@hourly'
end
if shortcut.is_a?(Numeric)

0 comments on commit a1aa561

Please sign in to comment.