class Chef::Resource::Cron
Public Class Methods
new(name, run_context=nil)
click to toggle source
Calls superclass method
Chef::Resource.new
# File lib/chef/resource/cron.rb, line 30 def initialize(name, run_context=nil) super @resource_name = :cron @action = :create @allowed_actions.push(:create, :delete) @minute = "*" @hour = "*" @day = "*" @month = "*" @weekday = "*" @command = nil @user = "root" @mailto = nil @path = nil @shell = nil @home = nil @time = nil @environment = {} end
Public Instance Methods
command(arg=nil)
click to toggle source
# File lib/chef/resource/cron.rb, line 182 def command(arg=nil) set_or_return( :command, arg, :kind_of => String ) end
day(arg=nil)
click to toggle source
# File lib/chef/resource/cron.rb, line 84 def day(arg=nil) if arg.is_a?(Integer) converted_arg = arg.to_s else converted_arg = arg end begin if integerize(arg) > 31 then raise RangeError end rescue ArgumentError end set_or_return( :day, converted_arg, :kind_of => String ) end
environment(arg=nil)
click to toggle source
# File lib/chef/resource/cron.rb, line 198 def environment(arg=nil) set_or_return( :environment, arg, :kind_of => Hash ) end
home(arg=nil)
click to toggle source
# File lib/chef/resource/cron.rb, line 166 def home(arg=nil) set_or_return( :home, arg, :kind_of => String ) end
hour(arg=nil)
click to toggle source
# File lib/chef/resource/cron.rb, line 67 def hour(arg=nil) if arg.is_a?(Integer) converted_arg = arg.to_s else converted_arg = arg end begin if integerize(arg) > 23 then raise RangeError end rescue ArgumentError end set_or_return( :hour, converted_arg, :kind_of => String ) end
mailto(arg=nil)
click to toggle source
# File lib/chef/resource/cron.rb, line 150 def mailto(arg=nil) set_or_return( :mailto, arg, :kind_of => String ) end
minute(arg=nil)
click to toggle source
# File lib/chef/resource/cron.rb, line 50 def minute(arg=nil) if arg.is_a?(Integer) converted_arg = arg.to_s else converted_arg = arg end begin if integerize(arg) > 59 then raise RangeError end rescue ArgumentError end set_or_return( :minute, converted_arg, :kind_of => String ) end
month(arg=nil)
click to toggle source
# File lib/chef/resource/cron.rb, line 101 def month(arg=nil) if arg.is_a?(Integer) converted_arg = arg.to_s else converted_arg = arg end begin if integerize(arg) > 12 then raise RangeError end rescue ArgumentError end set_or_return( :month, converted_arg, :kind_of => String ) end
path(arg=nil)
click to toggle source
# File lib/chef/resource/cron.rb, line 158 def path(arg=nil) set_or_return( :path, arg, :kind_of => String ) end
shell(arg=nil)
click to toggle source
# File lib/chef/resource/cron.rb, line 174 def shell(arg=nil) set_or_return( :shell, arg, :kind_of => String ) end
time(arg=nil)
click to toggle source
# File lib/chef/resource/cron.rb, line 142 def time(arg=nil) set_or_return( :time, arg, :equal_to => Chef::Provider::Cron::SPECIAL_TIME_VALUES ) end
user(arg=nil)
click to toggle source
# File lib/chef/resource/cron.rb, line 190 def user(arg=nil) set_or_return( :user, arg, :kind_of => String ) end
weekday(arg=nil)
click to toggle source
# File lib/chef/resource/cron.rb, line 118 def weekday(arg=nil) if arg.is_a?(Integer) converted_arg = arg.to_s else converted_arg = arg end begin error_message = "You provided '#{arg}' as a weekday, acceptable values are " error_message << Provider::Cron::WEEKDAY_SYMBOLS.map {|sym| ":#{sym.to_s}"}.join(', ') error_message << " and a string in crontab format" if (arg.is_a?(Symbol) && !Provider::Cron::WEEKDAY_SYMBOLS.include?(arg)) || (!arg.is_a?(Symbol) && integerize(arg) > 7) || (!arg.is_a?(Symbol) && integerize(arg) < 0) raise RangeError, error_message end rescue ArgumentError end set_or_return( :weekday, converted_arg, :kind_of => [String, Symbol] ) end
Private Instance Methods
integerize(integerish)
click to toggle source
On Ruby 1.8, Kernel#Integer will happily do this for you. On 1.9, no.
# File lib/chef/resource/cron.rb, line 209 def integerize(integerish) Integer(integerish) rescue TypeError 0 end