From 8d1fbe4586c91682cdda0cb271649e918fd9778b Mon Sep 17 00:00:00 2001 From: Markus Roberts Date: Fri, 9 Jul 2010 18:06:33 -0700 Subject: 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 --- lib/puppet/util/selinux.rb | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'lib/puppet/util/selinux.rb') diff --git a/lib/puppet/util/selinux.rb b/lib/puppet/util/selinux.rb index 7c6177f81..ab7e12d29 100644 --- a/lib/puppet/util/selinux.rb +++ b/lib/puppet/util/selinux.rb @@ -18,7 +18,7 @@ module Puppet::Util::SELinux if Selinux.is_selinux_enabled == 1 return true end - return false + false end # Retrieve and return the full context of the file. If we don't have @@ -29,7 +29,7 @@ module Puppet::Util::SELinux if retval == -1 return nil end - return retval[1] + retval[1] end # Retrieve and return the default context of the file. If we don't have @@ -51,7 +51,7 @@ module Puppet::Util::SELinux if retval == -1 return nil end - return retval[1] + retval[1] end # Take the full SELinux context returned from the tools and parse it @@ -70,7 +70,7 @@ module Puppet::Util::SELinux :seltype => $3, :selrange => $4, } - return ret[component] + ret[component] end # This updates the actual SELinux label on the file. You can update @@ -133,7 +133,7 @@ module Puppet::Util::SELinux set_selinux_context(file, new_context) return new_context end - return nil + nil end # Internal helper function to read and parse /proc/mounts @@ -168,7 +168,7 @@ module Puppet::Util::SELinux next if params[2] == 'rootfs' mntpoint[params[1]] = params[2] end - return mntpoint + mntpoint end def realpath(path) @@ -199,7 +199,7 @@ module Puppet::Util::SELinux return mnts[path] if mnts.has_key?(path) path = parent_directory(path) end - return mnts['/'] + mnts['/'] end # Check filesystem a path resides on for SELinux support against @@ -210,7 +210,7 @@ module Puppet::Util::SELinux fstype = find_fs(file) return false if fstype.nil? filesystems = ['ext2', 'ext3', 'ext4', 'gfs', 'gfs2', 'xfs', 'jfs'] - return filesystems.include?(fstype) + filesystems.include?(fstype) end end -- cgit