diff options
author | Markus Roberts <Markus@reality.com> | 2010-07-09 18:06:33 -0700 |
---|---|---|
committer | Markus Roberts <Markus@reality.com> | 2010-07-09 18:06:33 -0700 |
commit | 8d1fbe4586c91682cdda0cb271649e918fd9778b (patch) | |
tree | 314508ca21830874d9e4ec6e27880fede14193bd /lib/puppet/util/fileparsing.rb | |
parent | 889158ad57e33df083613d6f7d136b2e11aaa16a (diff) | |
download | puppet-8d1fbe4586c91682cdda0cb271649e918fd9778b.tar.gz puppet-8d1fbe4586c91682cdda0cb271649e918fd9778b.tar.xz puppet-8d1fbe4586c91682cdda0cb271649e918fd9778b.zip |
Code smell: Avoid explicit returns
Replaced 583 occurances of
(DEF)
(LINES)
return (.*)
end
with
3 Examples:
The code:
def consolidate_failures(failed)
filters = Hash.new { |h,k| h[k] = [] }
failed.each do |spec, failed_trace|
if f = test_files_for(failed).find { |f| failed_trace =~ Regexp.new(f) }
filters[f] << spec
break
end
end
return filters
end
becomes:
def consolidate_failures(failed)
filters = Hash.new { |h,k| h[k] = [] }
failed.each do |spec, failed_trace|
if f = test_files_for(failed).find { |f| failed_trace =~ Regexp.new(f) }
filters[f] << spec
break
end
end
filters
end
The code:
def retrieve
return_value = super
return_value = return_value[0] if return_value && return_value.is_a?(Array)
return return_value
end
becomes:
def retrieve
return_value = super
return_value = return_value[0] if return_value && return_value.is_a?(Array)
return_value
end
The code:
def fake_fstab
os = Facter['operatingsystem']
if os == "Solaris"
name = "solaris.fstab"
elsif os == "FreeBSD"
name = "freebsd.fstab"
else
# Catchall for other fstabs
name = "linux.fstab"
end
oldpath = @provider_class.default_target
return fakefile(File::join("data/types/mount", name))
end
becomes:
def fake_fstab
os = Facter['operatingsystem']
if os == "Solaris"
name = "solaris.fstab"
elsif os == "FreeBSD"
name = "freebsd.fstab"
else
# Catchall for other fstabs
name = "linux.fstab"
end
oldpath = @provider_class.default_target
fakefile(File::join("data/types/mount", name))
end
Diffstat (limited to 'lib/puppet/util/fileparsing.rb')
-rw-r--r-- | lib/puppet/util/fileparsing.rb | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/lib/puppet/util/fileparsing.rb b/lib/puppet/util/fileparsing.rb index c8ab53d6a..a5d7ca4ab 100644 --- a/lib/puppet/util/fileparsing.rb +++ b/lib/puppet/util/fileparsing.rb @@ -137,7 +137,7 @@ module Puppet::Util::FileParsing # Try to match a specific text line. def handle_text_line(line, record) - return line =~ record.match ? {:record_type => record.name, :line => line} : nil + line =~ record.match ? {:record_type => record.name, :line => line} : nil end # Try to match a record. @@ -248,7 +248,7 @@ module Puppet::Util::FileParsing end end - return nil + nil end # Define a new type of record. These lines get split into hashes. Valid @@ -295,7 +295,7 @@ module Puppet::Util::FileParsing text += line_separator if trailing_separator - return text + text end # Convert our parsed record into a text record. @@ -362,7 +362,7 @@ module Puppet::Util::FileParsing @record_types[record.name] = record @record_order << record - return record + record end # Retrieve the record object. |