Class CronParam
In: lib/puppet/type/cron.rb
Parent: Puppet::Property

A base class for all of the Cron parameters, since they all have similar argument checking going on.

Methods

Attributes

boundaries  [RW] 
default  [RW] 

Public Instance methods

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.

[Source]

     # File lib/puppet/type/cron.rb, line 90
 90:         def alphacheck(value, ary)
 91:             tmp = value.downcase
 92:             
 93:             # If they specified a shortened version of the name, then see
 94:             # if we can lengthen it (e.g., mon => monday).
 95:             if tmp.length == 3
 96:                 ary.each_with_index { |name, index|
 97:                     if name =~ /#{tmp}/i
 98:                         return index
 99:                     end
100:                 }
101:             else
102:                 if ary.include?(tmp)
103:                     return ary.index(tmp)
104:                 end
105:             end
106: 
107:             return false
108:         end

We have to override the parent method, because we consume the entire "should" array

[Source]

    # File lib/puppet/type/cron.rb, line 56
56:         def insync?(is)
57:             if defined? @should and @should
58:                 self.is_to_s(is) == self.should_to_s
59:             else
60:                 true
61:             end
62:         end

[Source]

     # File lib/puppet/type/cron.rb, line 125
125:         def is_to_s(currentvalue = @is)
126:             if currentvalue
127:                 unless currentvalue.is_a?(Array)
128:                     return currentvalue
129:                 end
130: 
131:                 if self.name == :command or currentvalue[0].is_a? Symbol
132:                     currentvalue[0]
133:                 else
134:                     currentvalue.join(",")
135:                 end
136:             else
137:                 nil
138:             end
139:         end

Verify that a number is within the specified limits. Return the number if it is, or false if it is not.

[Source]

    # File lib/puppet/type/cron.rb, line 79
79:         def limitcheck(num, lower, upper)
80:             if num >= lower and num <= upper
81:                 return num
82:             else
83:                 return false
84:             end
85:         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.

[Source]

    # File lib/puppet/type/cron.rb, line 67
67:         def numfix(num)
68:             if num =~ /^\d+$/
69:                 return num.to_i
70:             elsif num.is_a?(Integer)
71:                 return num
72:             else
73:                 return false
74:             end
75:         end

[Source]

     # File lib/puppet/type/cron.rb, line 141
141:         def should
142:             if @should and @should[0] == :absent
143:                 :absent
144:             else
145:                 @should
146:             end
147:         end

[Source]

     # File lib/puppet/type/cron.rb, line 149
149:         def should=(ary)
150:             super
151:             @should.flatten!
152:         end

[Source]

     # File lib/puppet/type/cron.rb, line 110
110:         def should_to_s(newvalue = @should)
111:             if newvalue
112:                 unless newvalue.is_a?(Array)
113:                     newvalue = [newvalue]
114:                 end
115:                 if self.name == :command or newvalue[0].is_a? Symbol
116:                     newvalue[0]
117:                 else
118:                     newvalue.join(",")
119:                 end
120:             else
121:                 nil
122:             end
123:         end

[Validate]