~ubuntu-branches/ubuntu/karmic/chef/karmic

« back to all changes in this revision

Viewing changes to chef/lib/chef/resource/cron.rb

  • Committer: Bazaar Package Importer
  • Author(s): Joshua Timberman
  • Date: 2009-08-12 12:18:48 UTC
  • Revision ID: james.westby@ubuntu.com-20090812121848-yl38hpd7nfsl51xz
Tags: upstream-0.7.8
ImportĀ upstreamĀ versionĀ 0.7.8

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#
 
2
# Author:: Bryan McLellan (btm@loftninjas.org)
 
3
# Copyright:: Copyright (c) 2009 Bryan McLellan
 
4
# License:: Apache License, Version 2.0
 
5
#
 
6
# Licensed under the Apache License, Version 2.0 (the "License");
 
7
# you may not use this file except in compliance with the License.
 
8
# You may obtain a copy of the License at
 
9
 
10
#     http://www.apache.org/licenses/LICENSE-2.0
 
11
 
12
# Unless required by applicable law or agreed to in writing, software
 
13
# distributed under the License is distributed on an "AS IS" BASIS,
 
14
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 
15
# See the License for the specific language governing permissions and
 
16
# limitations under the License.
 
17
#
 
18
 
 
19
require 'chef/resource'
 
20
 
 
21
class Chef
 
22
  class Resource
 
23
    class Cron < Chef::Resource
 
24
 
 
25
      def initialize(name, collection=nil, node=nil)
 
26
        super(name, collection, node)
 
27
        @resource_name = :cron
 
28
        @action = :create
 
29
        @allowed_actions.push(:create, :delete)
 
30
        @minute = "*"
 
31
        @hour = "*"
 
32
        @day = "*"
 
33
        @month = "*"
 
34
        @weekday = "*"
 
35
        @command = nil
 
36
        @user = "root"
 
37
      end
 
38
 
 
39
      def minute(arg=nil)
 
40
        if arg.is_a?(Integer)
 
41
          converted_arg = arg.to_s
 
42
        else
 
43
          converted_arg = arg
 
44
        end
 
45
        begin
 
46
          if Integer(arg) > 59 then raise RangeError end
 
47
        rescue ArgumentError
 
48
        end
 
49
        set_or_return(
 
50
          :minute,
 
51
          converted_arg,
 
52
          :kind_of => String
 
53
        )
 
54
      end
 
55
 
 
56
      def hour(arg=nil)
 
57
        if arg.is_a?(Integer)
 
58
          converted_arg = arg.to_s
 
59
        else
 
60
          converted_arg = arg
 
61
        end
 
62
        begin
 
63
          if Integer(arg) > 23 then raise RangeError end
 
64
        rescue ArgumentError
 
65
        end
 
66
        set_or_return(
 
67
          :hour,
 
68
          converted_arg,
 
69
          :kind_of => String
 
70
        )
 
71
      end
 
72
 
 
73
      def day(arg=nil)
 
74
        if arg.is_a?(Integer)
 
75
          converted_arg = arg.to_s
 
76
        else
 
77
          converted_arg = arg
 
78
        end
 
79
        begin
 
80
          if Integer(arg) > 31 then raise RangeError end
 
81
        rescue ArgumentError
 
82
        end
 
83
        set_or_return(
 
84
          :day,
 
85
          converted_arg,
 
86
          :kind_of => String
 
87
        )
 
88
      end
 
89
 
 
90
      def month(arg=nil)
 
91
        if arg.is_a?(Integer)
 
92
          converted_arg = arg.to_s
 
93
        else
 
94
          converted_arg = arg
 
95
        end
 
96
        begin
 
97
          if Integer(arg) > 12 then raise RangeError end
 
98
        rescue ArgumentError
 
99
        end
 
100
        set_or_return(
 
101
          :month,
 
102
          converted_arg,
 
103
          :kind_of => String
 
104
        )
 
105
      end
 
106
 
 
107
      def weekday(arg=nil)
 
108
        if arg.is_a?(Integer)
 
109
          converted_arg = arg.to_s
 
110
        else
 
111
          converted_arg = arg
 
112
        end
 
113
        begin
 
114
          if Integer(arg) > 7 then raise RangeError end
 
115
        rescue ArgumentError
 
116
        end
 
117
        set_or_return(
 
118
          :weekday,
 
119
          converted_arg,
 
120
          :kind_of => String
 
121
        )
 
122
      end
 
123
 
 
124
      def command(arg=nil)
 
125
        set_or_return(
 
126
          :command,
 
127
          arg,
 
128
          :kind_of => String
 
129
        )
 
130
      end
 
131
 
 
132
      def user(arg=nil)
 
133
        set_or_return(
 
134
          :user,
 
135
          arg,
 
136
          :kind_of => String
 
137
        )
 
138
      end
 
139
    end
 
140
  end
 
141
end
 
142
 
 
143