aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/puppet/provider/cron/crontab.rb16
-rw-r--r--lib/puppet/type/cron.rb13
-rw-r--r--spec/lib/puppet_spec/files.rb3
3 files changed, 20 insertions, 12 deletions
diff --git a/lib/puppet/provider/cron/crontab.rb b/lib/puppet/provider/cron/crontab.rb
index a664629..e2cb6b6 100644
--- a/lib/puppet/provider/cron/crontab.rb
+++ b/lib/puppet/provider/cron/crontab.rb
@@ -34,11 +34,16 @@ Puppet::Type.type(:cron).provide(:crontab, parent: Puppet::Provider::ParsedFile,
def post_parse(record)
time = record.delete(:time)
- if match = %r{@(\S+)}.match(time)
+ match = %r{@(\S+)}.match(time)
+ if match
# is there another way to access the constant?
Puppet::Type::Cron::ProviderCrontab::TIME_FIELDS.each { |f| record[f] = :absent }
record[:special] = match.captures[0]
- elsif match = %r{(\S+)\s+(\S+)\s+(\S+)\s+(\S+)\s+(\S+)}.match(time)
+ return record
+ end
+
+ match = %r{(\S+)\s+(\S+)\s+(\S+)\s+(\S+)\s+(\S+)}.match(time)
+ if match
record[:special] = :absent
Puppet::Type::Cron::ProviderCrontab::TIME_FIELDS.zip(match.captures).each do |field, value|
record[field] = if value == absent
@@ -47,10 +52,11 @@ Puppet::Type.type(:cron).provide(:crontab, parent: Puppet::Provider::ParsedFile,
value.split(',')
end
end
- else
- raise Puppet::Error, _('Line got parsed as a crontab entry but cannot be handled. Please file a bug with the contents of your crontab')
+
+ return record
end
- record
+
+ raise Puppet::Error, _('Line got parsed as a crontab entry but cannot be handled. Please file a bug with the contents of your crontab')
end
def pre_gen(record)
diff --git a/lib/puppet/type/cron.rb b/lib/puppet/type/cron.rb
index fada980..a811f94 100644
--- a/lib/puppet/type/cron.rb
+++ b/lib/puppet/type/cron.rb
@@ -178,7 +178,8 @@ Puppet::Type.newtype(:cron) do
return value unless self.class.boundaries
lower, upper = self.class.boundaries
retval = nil
- if num = numfix(value)
+ num = numfix(value)
+ if num
retval = limitcheck(num, lower, upper)
elsif respond_to?(:alpha)
# If it has an alpha method defined, then we check
@@ -396,7 +397,8 @@ Puppet::Type.newtype(:cron) do
defaultto do
if provider.is_a?(@resource.class.provider(:crontab))
- if val = @resource.should(:user)
+ val = @resource.should(:user)
+ if val
val
else
struct = Etc.getpwuid(Process.uid)
@@ -450,10 +452,9 @@ Puppet::Type.newtype(:cron) do
def value(name)
name = name.to_sym
ret = nil
- if obj = @parameters[name]
- ret = obj.should
-
- ret ||= obj.retrieve
+ obj = @parameters[name]
+ if obj
+ ret = obj.should || obj.retrieve
if ret == :absent
ret = nil
diff --git a/spec/lib/puppet_spec/files.rb b/spec/lib/puppet_spec/files.rb
index c91f583..f8dde8d 100644
--- a/spec/lib/puppet_spec/files.rb
+++ b/spec/lib/puppet_spec/files.rb
@@ -8,7 +8,7 @@ module PuppetSpec::Files
def self.cleanup
# rubocop:disable Style/GlobalVars
$global_tempfiles ||= []
- while path = $global_tempfiles.pop
+ $global_tempfiles.each do |path|
begin
Dir.unstub(:entries)
FileUtils.rm_rf path, secure: true
@@ -16,6 +16,7 @@ module PuppetSpec::Files
# nothing to do
end
end
+ $global_tempfiles = []
# rubocop:enable Style/GlobalVars
end