A base class for all of the Cron parameters, since they all have similar argument checking going on.
Verify that a value falls within the specified array. Does case insensitive matching, and supports matching either the entire word or the first three letters of the word.
# File lib/puppet/type/cron.rb, line 83 def alphacheck(value, ary) tmp = value.downcase # If they specified a shortened version of the name, then see # if we can lengthen it (e.g., mon => monday). if tmp.length == 3 ary.each_with_index { |name, index| if tmp.upcase == name[0..2].upcase return index end } else return ary.index(tmp) if ary.include?(tmp) end false end
We have to override the parent method, because we consume the entire “should” array
# File lib/puppet/type/cron.rb, line 57 def insync?(is) self.is_to_s(is) == self.should_to_s end
# File lib/puppet/type/cron.rb, line 114 def is_to_s(currentvalue = @is) if currentvalue return currentvalue unless currentvalue.is_a?(Array) if self.name == :command or currentvalue[0].is_a? Symbol currentvalue[0] else currentvalue.join(",") end else nil end end
Verify that a number is within the specified limits. Return the number if it is, or false if it is not.
# File lib/puppet/type/cron.rb, line 76 def limitcheck(num, lower, upper) (num >= lower and num <= upper) && num end
A method used to do parameter input handling. Converts integers in string form to actual integers, and returns the value if it’s an integer or false if it’s just a normal string.
# File lib/puppet/type/cron.rb, line 64 def numfix(num) if num =~ /^\d+$/ return num.to_i elsif num.is_a?(Integer) return num else return false end end
# File lib/puppet/type/cron.rb, line 128 def should if @should and @should[0] == :absent :absent else @should end end
# File lib/puppet/type/cron.rb, line 136 def should=(ary) super @should.flatten! end
# File lib/puppet/type/cron.rb, line 101 def should_to_s(newvalue = @should) if newvalue newvalue = [newvalue] unless newvalue.is_a?(Array) if self.name == :command or newvalue[0].is_a? Symbol newvalue[0] else newvalue.join(",") end else nil end end