summaryrefslogtreecommitdiffstats
path: root/lib/puppet/provider/nameservice.rb
diff options
context:
space:
mode:
authorMarkus Roberts <Markus@reality.com>2010-07-09 18:05:55 -0700
committerMarkus Roberts <Markus@reality.com>2010-07-09 18:05:55 -0700
commite8cf06336b64491a2dd7538a06651e0caaf6a48d (patch)
tree9f5d4c83d03fefa54c385462f60875056a58a82c /lib/puppet/provider/nameservice.rb
parenteefccf252527dc5b69af5959b0b0e2ddb5c91b74 (diff)
downloadpuppet-e8cf06336b64491a2dd7538a06651e0caaf6a48d.tar.gz
puppet-e8cf06336b64491a2dd7538a06651e0caaf6a48d.tar.xz
puppet-e8cf06336b64491a2dd7538a06651e0caaf6a48d.zip
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/provider/nameservice.rb')
-rw-r--r--lib/puppet/provider/nameservice.rb24
1 files changed, 12 insertions, 12 deletions
diff --git a/lib/puppet/provider/nameservice.rb b/lib/puppet/provider/nameservice.rb
index 8a759e4f3..dace6b512 100644
--- a/lib/puppet/provider/nameservice.rb
+++ b/lib/puppet/provider/nameservice.rb
@@ -45,7 +45,7 @@ class Puppet::Provider::NameService < Puppet::Provider
def options(name, hash)
unless resource_type.valid_parameter?(name)
- raise Puppet::DevError, "%s is not a valid attribute for %s" % [name, resource_type.name]
+ raise Puppet::DevError, "#{name} is not a valid attribute for #{resource_type.name}"
end
@options ||= {}
@options[name] ||= {}
@@ -61,16 +61,16 @@ class Puppet::Provider::NameService < Puppet::Provider
# for both users and groups.
def listbyname
names = []
- Etc.send("set%sent" % section())
+ Etc.send("set#{section()}ent")
begin
- while ent = Etc.send("get%sent" % section())
+ while ent = Etc.send("get#{section()}ent")
names << ent.name
if block_given?
yield ent.name
end
end
ensure
- Etc.send("end%sent" % section())
+ Etc.send("end#{section()}ent")
end
return names
@@ -110,7 +110,7 @@ class Puppet::Provider::NameService < Puppet::Provider
if @checks.include? name
block = @checks[name][:block]
unless block.call(value)
- raise ArgumentError, "Invalid value %s: %s" % [value, @checks[name][:error]]
+ raise ArgumentError, "Invalid value #{value}: #{@checks[name][:error]}"
end
end
end
@@ -123,7 +123,7 @@ class Puppet::Provider::NameService < Puppet::Provider
private
def op(property)
- @ops[property.name] || ("-" + property.name)
+ @ops[property.name] || ("-#{property.name}")
end
end
@@ -137,8 +137,8 @@ class Puppet::Provider::NameService < Puppet::Provider
else
if value = self.class.autogen_default(field)
return value
- elsif respond_to?("autogen_%s" % [field])
- return send("autogen_%s" % field)
+ elsif respond_to?("autogen_#{field}")
+ return send("autogen_#{field}")
else
return nil
end
@@ -155,7 +155,7 @@ class Puppet::Provider::NameService < Puppet::Provider
when :user; group = :passwd; method = :uid
when :group; group = :group; method = :gid
else
- raise Puppet::DevError, "Invalid resource name %s" % resource
+ raise Puppet::DevError, "Invalid resource name #{resource}"
end
# Make sure we don't use the same value multiple times
@@ -186,7 +186,7 @@ class Puppet::Provider::NameService < Puppet::Provider
begin
execute(self.addcmd)
rescue Puppet::ExecutionFailure => detail
- raise Puppet::Error, "Could not create %s %s: %s" % [@resource.class.name, @resource.name, detail]
+ raise Puppet::Error, "Could not create #{@resource.class.name} #{@resource.name}: #{detail}"
end
end
@@ -200,7 +200,7 @@ class Puppet::Provider::NameService < Puppet::Provider
begin
execute(self.deletecmd)
rescue Puppet::ExecutionFailure => detail
- raise Puppet::Error, "Could not delete %s %s: %s" % [@resource.class.name, @resource.name, detail]
+ raise Puppet::Error, "Could not delete #{@resource.class.name} #{@resource.name}: #{detail}"
end
end
@@ -304,7 +304,7 @@ class Puppet::Provider::NameService < Puppet::Provider
begin
execute(cmd)
rescue Puppet::ExecutionFailure => detail
- raise Puppet::Error, "Could not set %s on %s[%s]: %s" % [param, @resource.class.name, @resource.name, detail]
+ raise Puppet::Error, "Could not set #{param} on #{@resource.class.name}[#{@resource.name}]: #{detail}"
end
end
end