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/network | |
| 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/network')
| -rwxr-xr-x | lib/puppet/network/authstore.rb | 6 | ||||
| -rw-r--r-- | lib/puppet/network/client/ca.rb | 2 | ||||
| -rw-r--r-- | lib/puppet/network/format.rb | 2 | ||||
| -rw-r--r-- | lib/puppet/network/format_handler.rb | 2 | ||||
| -rw-r--r-- | lib/puppet/network/handler/ca.rb | 2 | ||||
| -rwxr-xr-x | lib/puppet/network/handler/filebucket.rb | 2 | ||||
| -rwxr-xr-x | lib/puppet/network/handler/fileserver.rb | 16 | ||||
| -rw-r--r-- | lib/puppet/network/handler/master.rb | 4 | ||||
| -rwxr-xr-x | lib/puppet/network/handler/runner.rb | 2 | ||||
| -rw-r--r-- | lib/puppet/network/handler/status.rb | 2 | ||||
| -rw-r--r-- | lib/puppet/network/http/api/v1.rb | 2 | ||||
| -rw-r--r-- | lib/puppet/network/http/handler.rb | 2 | ||||
| -rw-r--r-- | lib/puppet/network/http/mongrel/rest.rb | 2 | ||||
| -rw-r--r-- | lib/puppet/network/http_pool.rb | 2 | ||||
| -rw-r--r-- | lib/puppet/network/http_server/mongrel.rb | 2 | ||||
| -rw-r--r-- | lib/puppet/network/http_server/webrick.rb | 4 | ||||
| -rwxr-xr-x | lib/puppet/network/rights.rb | 6 | ||||
| -rw-r--r-- | lib/puppet/network/server.rb | 2 | ||||
| -rw-r--r-- | lib/puppet/network/xmlrpc/client.rb | 2 | ||||
| -rw-r--r-- | lib/puppet/network/xmlrpc/webrick_servlet.rb | 2 |
20 files changed, 33 insertions, 33 deletions
diff --git a/lib/puppet/network/authstore.rb b/lib/puppet/network/authstore.rb index 555a5df64..720145ed8 100755 --- a/lib/puppet/network/authstore.rb +++ b/lib/puppet/network/authstore.rb @@ -20,7 +20,7 @@ module Puppet store(:allow, pattern) end - return nil + nil end # Is a given combination of name and ip address allowed? If either input @@ -46,7 +46,7 @@ module Puppet end info "defaulting to no access for #{name}" - return false + false end # Deny a given pattern. @@ -97,7 +97,7 @@ module Puppet @declarations << Declaration.new(type, pattern) @declarations.sort! - return nil + nil end # A single declaration. Stores the info for a given declaration, diff --git a/lib/puppet/network/client/ca.rb b/lib/puppet/network/client/ca.rb index 1460e4d6e..ca5c7d5cd 100644 --- a/lib/puppet/network/client/ca.rb +++ b/lib/puppet/network/client/ca.rb @@ -50,7 +50,7 @@ class Puppet::Network::Client::CA < Puppet::Network::Client Puppet.settings.write(:hostcert) do |f| f.print cert end Puppet.settings.write(:localcacert) do |f| f.print cacert end - return @cert + @cert end end diff --git a/lib/puppet/network/format.rb b/lib/puppet/network/format.rb index 243671d1c..bdaee0fec 100644 --- a/lib/puppet/network/format.rb +++ b/lib/puppet/network/format.rb @@ -81,7 +81,7 @@ class Puppet::Network::Format return false unless required_method_present?(:render_method, klass, :instance) - return true + true end def supported?(klass) diff --git a/lib/puppet/network/format_handler.rb b/lib/puppet/network/format_handler.rb index c21979ea4..70e33a054 100644 --- a/lib/puppet/network/format_handler.rb +++ b/lib/puppet/network/format_handler.rb @@ -55,7 +55,7 @@ module Puppet::Network::FormatHandler @formats.each do |name, format| return format if format.extension == ext end - return nil + nil end # Provide a list of all formats. diff --git a/lib/puppet/network/handler/ca.rb b/lib/puppet/network/handler/ca.rb index c72171d5d..101cf6f8e 100644 --- a/lib/puppet/network/handler/ca.rb +++ b/lib/puppet/network/handler/ca.rb @@ -55,7 +55,7 @@ class Puppet::Network::Handler } # for now, just cheat and pass a fake IP address to allowed? - return auth.allowed?(hostname, "127.1.1.1") + auth.allowed?(hostname, "127.1.1.1") end def initialize(hash = {}) diff --git a/lib/puppet/network/handler/filebucket.rb b/lib/puppet/network/handler/filebucket.rb index 13fee1661..c0693ad7a 100755 --- a/lib/puppet/network/handler/filebucket.rb +++ b/lib/puppet/network/handler/filebucket.rb @@ -28,7 +28,7 @@ class Puppet::Network::Handler # :nodoc: def addfile(contents, path, client = nil, clientip = nil) contents = Base64.decode64(contents) if client bucket = Puppet::FileBucket::File.new(contents) - return bucket.save + bucket.save end # Return the contents associated with a given md5 sum. diff --git a/lib/puppet/network/handler/fileserver.rb b/lib/puppet/network/handler/fileserver.rb index b7a0c1387..efd71223f 100755 --- a/lib/puppet/network/handler/fileserver.rb +++ b/lib/puppet/network/handler/fileserver.rb @@ -84,7 +84,7 @@ class Puppet::Network::Handler return "" end - return metadata.attributes_with_tabs + metadata.attributes_with_tabs end # Create a new fileserving module. @@ -159,7 +159,7 @@ class Puppet::Network::Handler @mounts[name] = Mount.new(name, path) @mounts[name].info "Mounted #{path}" - return @mounts[name] + @mounts[name] end # Retrieve a file from the local disk and pass it to the remote @@ -235,7 +235,7 @@ class Puppet::Network::Handler env = (node = Puppet::Node.find(hostname)) ? node.environment : nil # And use the environment to look up the module. - return (mod = Puppet::Node::Environment.new(env).module(module_name) and mod.files?) ? @mounts[MODULES].copy(mod.name, mod.file_directory) : nil + (mod = Puppet::Node::Environment.new(env).module(module_name) and mod.files?) ? @mounts[MODULES].copy(mod.name, mod.file_directory) : nil end # Read the configuration file. @@ -458,7 +458,7 @@ class Puppet::Network::Handler # If there's no relative path name, then we're serving the mount itself. return full_path unless relative_path and relative_path != "/" - return File.join(full_path, relative_path) + File.join(full_path, relative_path) end # Create out object. It must have a name. @@ -505,7 +505,7 @@ class Puppet::Network::Handler # This, ah, might be completely redundant obj[:links] = links unless obj[:links] == links - return obj + obj end # Read the contents of the file at the relative path given. @@ -602,7 +602,7 @@ class Puppet::Network::Handler result = self.clone result.path = path result.instance_variable_set(:@name, name) - return result + result end # List the contents of the relative path +relpath+ of this mount. @@ -635,7 +635,7 @@ class Puppet::Network::Handler return [["/", File.stat(abspath).ftype]] end end - return nil + nil end def reclist(abspath, recurse, ignore) @@ -659,7 +659,7 @@ class Puppet::Network::Handler [ file, stat.ftype ] end - return ary.compact + ary.compact end end diff --git a/lib/puppet/network/handler/master.rb b/lib/puppet/network/handler/master.rb index 690e7079e..6f2c238a2 100644 --- a/lib/puppet/network/handler/master.rb +++ b/lib/puppet/network/handler/master.rb @@ -23,7 +23,7 @@ class Puppet::Network::Handler # Tell a client whether there's a fresh config for it def freshness(client = nil, clientip = nil) # Always force a recompile. Newer clients shouldn't do this (as of April 2008). - return Time.now.to_i + Time.now.to_i end def initialize(hash = {}) @@ -79,7 +79,7 @@ class Puppet::Network::Handler end end - return facts + facts end # Translate our configuration appropriately for sending back to a client. diff --git a/lib/puppet/network/handler/runner.rb b/lib/puppet/network/handler/runner.rb index 4f8247214..bc1a07ac5 100755 --- a/lib/puppet/network/handler/runner.rb +++ b/lib/puppet/network/handler/runner.rb @@ -24,7 +24,7 @@ class Puppet::Network::Handler runner.run - return runner.status + runner.status end end end diff --git a/lib/puppet/network/handler/status.rb b/lib/puppet/network/handler/status.rb index fbdc7a765..fe6c23dc3 100644 --- a/lib/puppet/network/handler/status.rb +++ b/lib/puppet/network/handler/status.rb @@ -9,7 +9,7 @@ class Puppet::Network::Handler } def status(client = nil, clientip = nil) - return 1 + 1 end end end diff --git a/lib/puppet/network/http/api/v1.rb b/lib/puppet/network/http/api/v1.rb index 265b297ec..577328589 100644 --- a/lib/puppet/network/http/api/v1.rb +++ b/lib/puppet/network/http/api/v1.rb @@ -45,7 +45,7 @@ module Puppet::Network::HTTP::API::V1 raise ArgumentError, "No support for plural #{http_method} operations" end - return method + method end def pluralize(indirection) diff --git a/lib/puppet/network/http/handler.rb b/lib/puppet/network/http/handler.rb index 66e0c720e..9f467372c 100644 --- a/lib/puppet/network/http/handler.rb +++ b/lib/puppet/network/http/handler.rb @@ -152,7 +152,7 @@ module Puppet::Network::HTTP::Handler rescue => detail Puppet.err "Could not resolve #{result[:ip]}: #{detail}" end - return result[:ip] + result[:ip] end private diff --git a/lib/puppet/network/http/mongrel/rest.rb b/lib/puppet/network/http/mongrel/rest.rb index 8668bf802..60367a1e8 100644 --- a/lib/puppet/network/http/mongrel/rest.rb +++ b/lib/puppet/network/http/mongrel/rest.rb @@ -87,6 +87,6 @@ class Puppet::Network::HTTP::MongrelREST < Mongrel::HttpHandler result[:authenticated] = false end - return result + result end end diff --git a/lib/puppet/network/http_pool.rb b/lib/puppet/network/http_pool.rb index 2bccba2e8..b4f40c6fe 100644 --- a/lib/puppet/network/http_pool.rb +++ b/lib/puppet/network/http_pool.rb @@ -111,6 +111,6 @@ module Puppet::Network::HttpPool http_cache[key] = http if keep_alive? - return http + http end end diff --git a/lib/puppet/network/http_server/mongrel.rb b/lib/puppet/network/http_server/mongrel.rb index 23ab40bb0..0f81bf2a2 100644 --- a/lib/puppet/network/http_server/mongrel.rb +++ b/lib/puppet/network/http_server/mongrel.rb @@ -137,7 +137,7 @@ module Puppet::Network info = Puppet::Network::ClientRequest.new(client, ip, valid) - return info + info end # Taken from XMLRPC::ParseContentType diff --git a/lib/puppet/network/http_server/webrick.rb b/lib/puppet/network/http_server/webrick.rb index df7a87bf2..e622b7127 100644 --- a/lib/puppet/network/http_server/webrick.rb +++ b/lib/puppet/network/http_server/webrick.rb @@ -33,7 +33,7 @@ module Puppet store.add_file(Puppet[:localcacert]) store.add_crl(crl) - return store + store end # Set up the http log. @@ -60,7 +60,7 @@ module Puppet log = WEBrick::Log.new(*args) - return log + log end # Create our server, yo. diff --git a/lib/puppet/network/rights.rb b/lib/puppet/network/rights.rb index 2c781b390..63ebae892 100755 --- a/lib/puppet/network/rights.rb +++ b/lib/puppet/network/rights.rb @@ -35,7 +35,7 @@ class Rights # if we didn't find the right acl raise end - return true + true end def fail_on_deny(name, args = {}) @@ -235,7 +235,7 @@ class Rights return self.key == namespace_to_key(key) if acl_type == :name # otherwise match with the regex - return self.key.match(key) + self.key.match(key) end def namespace_to_key(key) @@ -254,7 +254,7 @@ class Rights # sort by creation order (ie first match appearing in the file will win) # that is don't sort, in which case the sort algorithm will order in the # natural array order (ie the creation order) - return 0 + 0 end def ==(name) diff --git a/lib/puppet/network/server.rb b/lib/puppet/network/server.rb index dfc7e1008..9f4b5243b 100644 --- a/lib/puppet/network/server.rb +++ b/lib/puppet/network/server.rb @@ -160,6 +160,6 @@ class Puppet::Network::Server def determine_bind_address tmp = Puppet[:bindaddress] return tmp if tmp != "" - return server_type.to_s == "webrick" ? "0.0.0.0" : "127.0.0.1" + server_type.to_s == "webrick" ? "0.0.0.0" : "127.0.0.1" end end diff --git a/lib/puppet/network/xmlrpc/client.rb b/lib/puppet/network/xmlrpc/client.rb index 86b1fbd0b..e19275759 100644 --- a/lib/puppet/network/xmlrpc/client.rb +++ b/lib/puppet/network/xmlrpc/client.rb @@ -40,7 +40,7 @@ module Puppet::Network } } - return newclient + newclient end def self.handler_class(handler) diff --git a/lib/puppet/network/xmlrpc/webrick_servlet.rb b/lib/puppet/network/xmlrpc/webrick_servlet.rb index a3022dbe9..e7fb2ae9c 100644 --- a/lib/puppet/network/xmlrpc/webrick_servlet.rb +++ b/lib/puppet/network/xmlrpc/webrick_servlet.rb @@ -107,7 +107,7 @@ module Puppet::Network::XMLRPC info = Puppet::Network::ClientRequest.new(client, clientip, valid) - return info + info end end end |
