summaryrefslogtreecommitdiffstats
path: root/lib/puppet/util/ldap
diff options
context:
space:
mode:
authorMarkus Roberts <Markus@reality.com>2010-07-09 18:06:37 -0700
committerMarkus Roberts <Markus@reality.com>2010-07-09 18:06:37 -0700
commit07b15bf6fa2a2183f73fcb9b6740c7df75c8b47b (patch)
treef4f20be112f0c8832cb2e9681935a04bb0d197cf /lib/puppet/util/ldap
parent8d1fbe4586c91682cdda0cb271649e918fd9778b (diff)
downloadpuppet-07b15bf6fa2a2183f73fcb9b6740c7df75c8b47b.tar.gz
puppet-07b15bf6fa2a2183f73fcb9b6740c7df75c8b47b.tar.xz
puppet-07b15bf6fa2a2183f73fcb9b6740c7df75c8b47b.zip
Code smell: Avoid unneeded blocks
Replaced 45 occurances of (DEF) begin (LINES) rescue(.*) (LINES) end end with 3 Examples: The code: def find(name) begin self.const_get(name.to_s.capitalize) rescue puts "Unable to find application '#{name.to_s}'." Kernel::exit(1) end end becomes: def find(name) self.const_get(name.to_s.capitalize) rescue puts "Unable to find application '#{name.to_s}'." Kernel::exit(1) end The code: def exit_on_fail(message, code = 1) begin yield rescue RuntimeError, NotImplementedError => detail puts detail.backtrace if Puppet[:trace] $stderr.puts "Could not #{message}: #{detail}" exit(code) end end becomes: def exit_on_fail(message, code = 1) yield rescue RuntimeError, NotImplementedError => detail puts detail.backtrace if Puppet[:trace] $stderr.puts "Could not #{message}: #{detail}" exit(code) end The code: def start begin case ssl when :tls @connection = LDAP::SSLConn.new(host, port, true) when true @connection = LDAP::SSLConn.new(host, port) else @connection = LDAP::Conn.new(host, port) end @connection.set_option(LDAP::LDAP_OPT_PROTOCOL_VERSION, 3) @connection.set_option(LDAP::LDAP_OPT_REFERRALS, LDAP::LDAP_OPT_ON) @connection.simple_bind(user, password) rescue => detail raise Puppet::Error, "Could not connect to LDAP: #{detail}" end end becomes: def start case ssl when :tls @connection = LDAP::SSLConn.new(host, port, true) when true @connection = LDAP::SSLConn.new(host, port) else @connection = LDAP::Conn.new(host, port) end @connection.set_option(LDAP::LDAP_OPT_PROTOCOL_VERSION, 3) @connection.set_option(LDAP::LDAP_OPT_REFERRALS, LDAP::LDAP_OPT_ON) @connection.simple_bind(user, password) rescue => detail raise Puppet::Error, "Could not connect to LDAP: #{detail}" end
Diffstat (limited to 'lib/puppet/util/ldap')
-rw-r--r--lib/puppet/util/ldap/connection.rb4
1 files changed, 1 insertions, 3 deletions
diff --git a/lib/puppet/util/ldap/connection.rb b/lib/puppet/util/ldap/connection.rb
index 4f71069ef..624bc6f14 100644
--- a/lib/puppet/util/ldap/connection.rb
+++ b/lib/puppet/util/ldap/connection.rb
@@ -60,7 +60,6 @@ class Puppet::Util::Ldap::Connection
# Start our ldap connection.
def start
- begin
case ssl
when :tls
@connection = LDAP::SSLConn.new(host, port, true)
@@ -72,8 +71,7 @@ class Puppet::Util::Ldap::Connection
@connection.set_option(LDAP::LDAP_OPT_PROTOCOL_VERSION, 3)
@connection.set_option(LDAP::LDAP_OPT_REFERRALS, LDAP::LDAP_OPT_ON)
@connection.simple_bind(user, password)
- rescue => detail
+ rescue => detail
raise Puppet::Error, "Could not connect to LDAP: #{detail}"
- end
end
end