summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarkus Roberts <Markus@reality.com>2010-07-09 18:06:56 -0700
committerMarkus Roberts <Markus@reality.com>2010-07-09 18:06:56 -0700
commitc3e2353afb7fc2fb12efd1eb2bc5c342c792fb3b (patch)
tree4d328a1598165cf7e40363ef995b180322df168a
parent42a539061293f8e745a9dc5b97b4415b6a275e04 (diff)
downloadpuppet-c3e2353afb7fc2fb12efd1eb2bc5c342c792fb3b.tar.gz
puppet-c3e2353afb7fc2fb12efd1eb2bc5c342c792fb3b.tar.xz
puppet-c3e2353afb7fc2fb12efd1eb2bc5c342c792fb3b.zip
Code smell: Use &&= for dependent initialization
Replaced 6 occurances of ([$@]?\w+) += +(.*) +(if +\1|unless +\1.nil\?)$ with \1 &&= \2 3 Examples: The code: end becomes: end The code: becomes: The code: res becomes: res
-rwxr-xr-xlib/puppet/type/file/mode.rb2
-rwxr-xr-xlib/puppet/type/schedule.rb2
-rw-r--r--lib/puppet/util/rdoc/generators/puppet_generator.rb2
-rw-r--r--lib/puppet/util/settings.rb6
4 files changed, 6 insertions, 6 deletions
diff --git a/lib/puppet/type/file/mode.rb b/lib/puppet/type/file/mode.rb
index 03cb63f4b..31209f42e 100755
--- a/lib/puppet/type/file/mode.rb
+++ b/lib/puppet/type/file/mode.rb
@@ -99,7 +99,7 @@ module Puppet
if stat = @resource.stat(false)
unless defined?(@fixed)
- @should = @should.collect { |s| self.dirmask(s) } if @should
+ @should &&= @should.collect { |s| self.dirmask(s) }
end
return stat.mode & 007777
else
diff --git a/lib/puppet/type/schedule.rb b/lib/puppet/type/schedule.rb
index f66b5b0ad..bcc62ce69 100755
--- a/lib/puppet/type/schedule.rb
+++ b/lib/puppet/type/schedule.rb
@@ -331,7 +331,7 @@ module Puppet
def match?(previous = nil, now = nil)
# If we've got a value, then convert it to a Time instance
- previous = Time.at(previous) if previous
+ previous &&= Time.at(previous)
now ||= Time.now
diff --git a/lib/puppet/util/rdoc/generators/puppet_generator.rb b/lib/puppet/util/rdoc/generators/puppet_generator.rb
index 614c8ccec..a956241a0 100644
--- a/lib/puppet/util/rdoc/generators/puppet_generator.rb
+++ b/lib/puppet/util/rdoc/generators/puppet_generator.rb
@@ -873,7 +873,7 @@ module Generators
def find_symbol(symbol, method=nil)
res = @context.parent.find_symbol(symbol, method)
- res = res.viewer if res
+ res &&= res.viewer
res
end
diff --git a/lib/puppet/util/settings.rb b/lib/puppet/util/settings.rb
index 7c70dfa8f..80cab1976 100644
--- a/lib/puppet/util/settings.rb
+++ b/lib/puppet/util/settings.rb
@@ -137,7 +137,7 @@ class Puppet::Util::Settings
# Handle a command-line argument.
def handlearg(opt, value = nil)
@cache.clear
- value = munge_value(value) if value
+ value &&= munge_value(value)
str = opt.sub(/^--/,'')
bool = true
@@ -658,7 +658,7 @@ if @config.include?(:run_mode)
def uninterpolated_value(param, environment = nil)
param = param.to_sym
- environment = environment.to_sym if environment
+ environment &&= environment.to_sym
# See if we can find it within our searchable list of values
val = catch :foundval do
@@ -682,7 +682,7 @@ if @config.include?(:run_mode)
# in which to search before the other configuration sections.
def value(param, environment = nil)
param = param.to_sym
- environment = environment.to_sym if environment
+ environment &&= environment.to_sym
# Short circuit to nil for undefined parameters.
return nil unless @config.include?(param)