summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTim Smith <tsmith@chef.io>2018-08-13 12:05:09 -0700
committerTim Smith <tsmith@chef.io>2018-08-13 12:44:18 -0700
commit1ef7f2dbeb5e36857fd1bee784726de3d462ce96 (patch)
treee306a0d1940288d1559c2a720c8511cb4a703b3a
parent5d1938b3f00f726e0ae8c4bf1f460ac663f13c56 (diff)
downloadchef-1ef7f2dbeb5e36857fd1bee784726de3d462ce96.tar.gz
Self the callback methods
Signed-off-by: Tim Smith <tsmith@chef.io>
-rw-r--r--lib/chef/resource/cron_d.rb96
1 files changed, 48 insertions, 48 deletions
diff --git a/lib/chef/resource/cron_d.rb b/lib/chef/resource/cron_d.rb
index f8f26290c9..5c11fb95c4 100644
--- a/lib/chef/resource/cron_d.rb
+++ b/lib/chef/resource/cron_d.rb
@@ -27,6 +27,54 @@ class Chef
introduced "14.4"
description "Use the cron_d resource to manage cron definitions in /etc/cron.d. This is similar to the 'cron' resource, but it does not use the monolithic /etc/crontab file."
+ def self.validate_numeric(spec, min, max)
+ return true if spec == "*"
+ # binding.pry
+ if spec.respond_to? :to_int
+ return false unless spec >= min && spec <= max
+ return true
+ end
+
+ # Lists of invidual values, ranges, and step values all share the validity range for type
+ spec.split(%r{\/|-|,}).each do |x|
+ next if x == "*"
+ return false unless x =~ /^\d+$/
+ x = x.to_i
+ return false unless x >= min && x <= max
+ end
+ true
+ end
+
+ def self.validate_month(spec)
+ return true if spec == "*"
+ if spec.respond_to? :to_int
+ validate_numeric(spec, 1, 12)
+ elsif spec.respond_to? :to_str
+ return true if spec == "*"
+ # Named abbreviations are permitted but not as part of a range or with stepping
+ return true if %w{jan feb mar apr may jun jul aug sep oct nov dec}.include? spec.downcase
+ # 1-12 are legal for months
+ validate_numeric(spec, 1, 12)
+ else
+ false
+ end
+ end
+
+ def self.validate_dow(spec)
+ return true if spec == "*"
+ if spec.respond_to? :to_int
+ validate_numeric(spec, 0, 7)
+ elsif spec.respond_to? :to_str
+ return true if spec == "*"
+ # Named abbreviations are permitted but not as part of a range or with stepping
+ return true if %w{sun mon tue wed thu fri sat}.include? spec.downcase
+ # 0-7 are legal for days of week
+ validate_numeric(spec, 0, 7)
+ else
+ false
+ end
+ end
+
property :cron_name, String,
description: "Set the name of the cron job. If this isn't specified we'll use the resource name.",
name_property: true
@@ -102,54 +150,6 @@ class Chef
raise ArgumentError, "The 'cookbook' property for the cron_d resource is no longer supported now that this resource ships in Chef itself." if new_resource.cookbook
end
- def validate_numeric(spec, min, max)
- return true if spec == "*"
- # binding.pry
- if spec.respond_to? :to_int
- return false unless spec >= min && spec <= max
- return true
- end
-
- # Lists of invidual values, ranges, and step values all share the validity range for type
- spec.split(%r{\/|-|,}).each do |x|
- next if x == "*"
- return false unless x =~ /^\d+$/
- x = x.to_i
- return false unless x >= min && x <= max
- end
- true
- end
-
- def validate_month(spec)
- return true if spec == "*"
- if spec.respond_to? :to_int
- validate_numeric(spec, 1, 12)
- elsif spec.respond_to? :to_str
- return true if spec == "*"
- # Named abbreviations are permitted but not as part of a range or with stepping
- return true if %w{jan feb mar apr may jun jul aug sep oct nov dec}.include? spec.downcase
- # 1-12 are legal for months
- validate_numeric(spec, 1, 12)
- else
- false
- end
- end
-
- def validate_dow(spec)
- return true if spec == "*"
- if spec.respond_to? :to_int
- validate_numeric(spec, 0, 7)
- elsif spec.respond_to? :to_str
- return true if spec == "*"
- # Named abbreviations are permitted but not as part of a range or with stepping
- return true if %w{sun mon tue wed thu fri sat}.include? spec.downcase
- # 0-7 are legal for days of week
- validate_numeric(spec, 0, 7)
- else
- false
- end
- end
-
action :create do
create_template(:create)
end