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/selinux.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/selinux.rb')
-rw-r--r-- | lib/puppet/util/selinux.rb | 16 |
1 files changed, 8 insertions, 8 deletions
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 |