diff options
| author | Markus Roberts <Markus@reality.com> | 2010-07-09 18:05:55 -0700 |
|---|---|---|
| committer | Markus Roberts <Markus@reality.com> | 2010-07-09 18:05:55 -0700 |
| commit | e8cf06336b64491a2dd7538a06651e0caaf6a48d (patch) | |
| tree | 9f5d4c83d03fefa54c385462f60875056a58a82c /lib/puppet/network/http | |
| parent | eefccf252527dc5b69af5959b0b0e2ddb5c91b74 (diff) | |
Code smell: Use string interpolation
* Replaced 83 occurances of
(.*)" *[+] *([$@]?[\w_0-9.:]+?)(.to_s\b)?(?! *[*(%\w_0-9.:{\[])
with
\1#{\2}"
3 Examples:
The code:
puts "PUPPET " + status + ": " + process + ", " + state
becomes:
puts "PUPPET " + status + ": " + process + ", #{state}"
The code:
puts "PUPPET " + status + ": #{process}" + ", #{state}"
becomes:
puts "PUPPET #{status}" + ": #{process}" + ", #{state}"
The code:
}.compact.join( "\n" ) + "\n" + t + "]\n"
becomes:
}.compact.join( "\n" ) + "\n#{t}" + "]\n"
* Replaced 21 occurances of (.*)" *[+] *" with \1
3 Examples:
The code:
puts "PUPPET #{status}" + ": #{process}" + ", #{state}"
becomes:
puts "PUPPET #{status}" + ": #{process}, #{state}"
The code:
puts "PUPPET #{status}" + ": #{process}, #{state}"
becomes:
puts "PUPPET #{status}: #{process}, #{state}"
The code:
res = self.class.name + ": #{@name}" + "\n"
becomes:
res = self.class.name + ": #{@name}\n"
* Don't use string concatenation to split lines unless they would be very long.
Replaced 11 occurances of
(.*)(['"]) *[+]
*(['"])(.*)
with
3 Examples:
The code:
o.define_head "The check_puppet Nagios plug-in checks that specified " +
"Puppet process is running and the state file is no " +
becomes:
o.define_head "The check_puppet Nagios plug-in checks that specified Puppet process is running and the state file is no " +
The code:
o.separator "Mandatory arguments to long options are mandatory for " +
"short options too."
becomes:
o.separator "Mandatory arguments to long options are mandatory for short options too."
The code:
o.define_head "The check_puppet Nagios plug-in checks that specified Puppet process is running and the state file is no " +
"older than specified interval."
becomes:
o.define_head "The check_puppet Nagios plug-in checks that specified Puppet process is running and the state file is no older than specified interval."
* Replaced no occurances of do (.*?) end with {\1}
* Replaced 1488 occurances of
"([^"\n]*%s[^"\n]*)" *% *(.+?)(?=$| *\b(do|if|while|until|unless|#)\b)
with
20 Examples:
The code:
args[0].split(/\./).map do |s| "dc=%s"%[s] end.join(",")
becomes:
args[0].split(/\./).map do |s| "dc=#{s}" end.join(",")
The code:
puts "%s" % Puppet.version
becomes:
puts "#{Puppet.version}"
The code:
raise "Could not find information for %s" % node
becomes:
raise "Could not find information for #{node}"
The code:
raise Puppet::Error, "Cannot create %s: basedir %s is a file" % [dir, File.join(path)]
becomes:
raise Puppet::Error, "Cannot create #{dir}: basedir #{File.join(path)} is a file"
The code:
Puppet.err "Could not run %s: %s" % [client_class, detail]
becomes:
Puppet.err "Could not run #{client_class}: #{detail}"
The code:
raise "Could not find handler for %s" % arg
becomes:
raise "Could not find handler for #{arg}"
The code:
Puppet.err "Will not start without authorization file %s" % Puppet[:authconfig]
becomes:
Puppet.err "Will not start without authorization file #{Puppet[:authconfig]}"
The code:
raise Puppet::Error, "Could not deserialize catalog from pson: %s" % detail
becomes:
raise Puppet::Error, "Could not deserialize catalog from pson: #{detail}"
The code:
raise "Could not find facts for %s" % Puppet[:certname]
becomes:
raise "Could not find facts for #{Puppet[:certname]}"
The code:
raise ArgumentError, "%s is not readable" % path
becomes:
raise ArgumentError, "#{path} is not readable"
The code:
raise ArgumentError, "Invalid handler %s" % name
becomes:
raise ArgumentError, "Invalid handler #{name}"
The code:
debug "Executing '%s' in zone %s with '%s'" % [command, @resource[:name], str]
becomes:
debug "Executing '#{command}' in zone #{@resource[:name]} with '#{str}'"
The code:
raise Puppet::Error, "unknown cert type '%s'" % hash[:type]
becomes:
raise Puppet::Error, "unknown cert type '#{hash[:type]}'"
The code:
Puppet.info "Creating a new certificate request for %s" % Puppet[:certname]
becomes:
Puppet.info "Creating a new certificate request for #{Puppet[:certname]}"
The code:
"Cannot create alias %s: object already exists" % [name]
becomes:
"Cannot create alias #{name}: object already exists"
The code:
return "replacing from source %s with contents %s" % [metadata.source, metadata.checksum]
becomes:
return "replacing from source #{metadata.source} with contents #{metadata.checksum}"
The code:
it "should have a %s parameter" % param do
becomes:
it "should have a #{param} parameter" do
The code:
describe "when registring '%s' messages" % log do
becomes:
describe "when registring '#{log}' messages" do
The code:
paths = %w{a b c d e f g h}.collect { |l| "/tmp/iteration%stest" % l }
becomes:
paths = %w{a b c d e f g h}.collect { |l| "/tmp/iteration#{l}test" }
The code:
assert_raise(Puppet::Error, "Check '%s' did not fail on false" % check) do
becomes:
assert_raise(Puppet::Error, "Check '#{check}' did not fail on false") do
Diffstat (limited to 'lib/puppet/network/http')
| -rw-r--r-- | lib/puppet/network/http/api/v1.rb | 10 | ||||
| -rw-r--r-- | lib/puppet/network/http/handler.rb | 14 | ||||
| -rw-r--r-- | lib/puppet/network/http/rack.rb | 2 | ||||
| -rw-r--r-- | lib/puppet/network/http/rack/xmlrpc.rb | 6 | ||||
| -rw-r--r-- | lib/puppet/network/http/webrick.rb | 4 |
5 files changed, 18 insertions, 18 deletions
diff --git a/lib/puppet/network/http/api/v1.rb b/lib/puppet/network/http/api/v1.rb index 6a5ff156a..25e27c486 100644 --- a/lib/puppet/network/http/api/v1.rb +++ b/lib/puppet/network/http/api/v1.rb @@ -19,14 +19,14 @@ module Puppet::Network::HTTP::API::V1 def uri2indirection(http_method, uri, params) environment, indirection, key = uri.split("/", 4)[1..-1] # the first field is always nil because of the leading slash - raise ArgumentError, "The environment must be purely alphanumeric, not '%s'" % environment unless environment =~ /^\w+$/ - raise ArgumentError, "The indirection name must be purely alphanumeric, not '%s'" % indirection unless indirection =~ /^\w+$/ + raise ArgumentError, "The environment must be purely alphanumeric, not '#{environment}'" unless environment =~ /^\w+$/ + raise ArgumentError, "The indirection name must be purely alphanumeric, not '#{indirection}'" unless indirection =~ /^\w+$/ method = indirection_method(http_method, indirection) params[:environment] = environment - raise ArgumentError, "No request key specified in %s" % uri if key == "" or key.nil? + raise ArgumentError, "No request key specified in #{uri}" if key == "" or key.nil? key = URI.unescape(key) @@ -40,11 +40,11 @@ module Puppet::Network::HTTP::API::V1 def indirection_method(http_method, indirection) unless METHOD_MAP[http_method] - raise ArgumentError, "No support for http method %s" % http_method + raise ArgumentError, "No support for http method #{http_method}" end unless method = METHOD_MAP[http_method][plurality(indirection)] - raise ArgumentError, "No support for plural %s operations" % http_method + raise ArgumentError, "No support for plural #{http_method} operations" end return method diff --git a/lib/puppet/network/http/handler.rb b/lib/puppet/network/http/handler.rb index a76fefdcc..66e0c720e 100644 --- a/lib/puppet/network/http/handler.rb +++ b/lib/puppet/network/http/handler.rb @@ -37,14 +37,14 @@ module Puppet::Network::HTTP::Handler return format end - raise "No specified acceptable formats (%s) are functional on this machine" % header + raise "No specified acceptable formats (#{header}) are functional on this machine" end def request_format(request) if header = content_type_header(request) header.gsub!(/\s*;.*$/,'') # strip any charset format = Puppet::Network::FormatHandler.mime(header) - raise "Client sent a mime-type (%s) that doesn't correspond to a format we support" % header if format.nil? + raise "Client sent a mime-type (#{header}) that doesn't correspond to a format we support" if format.nil? return format.name.to_s if format.suitable? end @@ -65,7 +65,7 @@ module Puppet::Network::HTTP::Handler check_authorization(indirection_request) - send("do_%s" % indirection_request.method, indirection_request, request, response) + send("do_#{indirection_request.method}", indirection_request, request, response) rescue SystemExit,NoMemoryError raise rescue Exception => e @@ -99,8 +99,8 @@ module Puppet::Network::HTTP::Handler # Execute our find. def do_find(indirection_request, request, response) unless result = indirection_request.model.find(indirection_request.key, indirection_request.to_hash) - Puppet.info("Could not find %s for '%s'" % [indirection_request.indirection_name, indirection_request.key]) - return do_exception(response, "Could not find %s %s" % [indirection_request.indirection_name, indirection_request.key], 404) + Puppet.info("Could not find #{indirection_request.indirection_name} for '#{indirection_request.key}'") + return do_exception(response, "Could not find #{indirection_request.indirection_name} #{indirection_request.key}", 404) end # The encoding of the result must include the format to use, @@ -117,7 +117,7 @@ module Puppet::Network::HTTP::Handler result = indirection_request.model.search(indirection_request.key, indirection_request.to_hash) if result.nil? or (result.is_a?(Array) and result.empty?) - return do_exception(response, "Could not find instances in %s with '%s'" % [indirection_request.indirection_name, indirection_request.to_hash.inspect], 404) + return do_exception(response, "Could not find instances in #{indirection_request.indirection_name} with '#{indirection_request.to_hash.inspect}'", 404) end format = format_to_use(request) @@ -150,7 +150,7 @@ module Puppet::Network::HTTP::Handler begin return Resolv.getname(result[:ip]) rescue => detail - Puppet.err "Could not resolve %s: %s" % [result[:ip], detail] + Puppet.err "Could not resolve #{result[:ip]}: #{detail}" end return result[:ip] end diff --git a/lib/puppet/network/http/rack.rb b/lib/puppet/network/http/rack.rb index 756b66814..a5f69612d 100644 --- a/lib/puppet/network/http/rack.rb +++ b/lib/puppet/network/http/rack.rb @@ -54,7 +54,7 @@ class Puppet::Network::HTTP::Rack # log what happened Puppet.err "Puppet Server (Rack): Internal Server Error: Unhandled Exception: \"%s\"" % detail.message Puppet.err "Backtrace:" - detail.backtrace.each { |line| Puppet.err " > %s" % line } + detail.backtrace.each { |line| Puppet.err " > #{line}" } end response.finish() end diff --git a/lib/puppet/network/http/rack/xmlrpc.rb b/lib/puppet/network/http/rack/xmlrpc.rb index 4fc9e82fc..49eb6fe49 100644 --- a/lib/puppet/network/http/rack/xmlrpc.rb +++ b/lib/puppet/network/http/rack/xmlrpc.rb @@ -6,9 +6,9 @@ class Puppet::Network::HTTP::RackXMLRPC < Puppet::Network::HTTP::RackHttpHandler def initialize(handlers) @xmlrpc_server = Puppet::Network::XMLRPCServer.new handlers.each do |name| - Puppet.debug " -> register xmlrpc namespace %s" % name + Puppet.debug " -> register xmlrpc namespace #{name}" unless handler = Puppet::Network::Handler.handler(name) - raise ArgumentError, "Invalid XMLRPC handler %s" % name + raise ArgumentError, "Invalid XMLRPC handler #{name}" end @xmlrpc_server.add_handler(handler.interface, handler.new({})) end @@ -52,7 +52,7 @@ class Puppet::Network::HTTP::RackXMLRPC < Puppet::Network::HTTP::RackHttpHandler begin node = Resolv.getname(ip) rescue => detail - Puppet.err "Could not resolve %s: %s" % [ip, detail] + Puppet.err "Could not resolve #{ip}: #{detail}" node = "unknown" end authenticated = false diff --git a/lib/puppet/network/http/webrick.rb b/lib/puppet/network/http/webrick.rb index effe92434..d0533f7ff 100644 --- a/lib/puppet/network/http/webrick.rb +++ b/lib/puppet/network/http/webrick.rb @@ -98,7 +98,7 @@ class Puppet::Network::HTTP::WEBrick # Get the cached copy. We know it's been generated, too. host = Puppet::SSL::Host.localhost - raise Puppet::Error, "Could not retrieve certificate for %s and not running on a valid certificate authority" % host.name unless host.certificate + raise Puppet::Error, "Could not retrieve certificate for #{host.name} and not running on a valid certificate authority" unless host.certificate results[:SSLPrivateKey] = host.key.content results[:SSLCertificate] = host.certificate.content @@ -134,7 +134,7 @@ class Puppet::Network::HTTP::WEBrick def xmlrpc_servlet handlers = @xmlrpc_handlers.collect { |handler| unless hclass = Puppet::Network::Handler.handler(handler) - raise "Invalid xmlrpc handler %s" % handler + raise "Invalid xmlrpc handler #{handler}" end hclass.new({}) } |
