diff options
author | Markus Roberts <Markus@reality.com> | 2010-07-09 18:06:38 -0700 |
---|---|---|
committer | Markus Roberts <Markus@reality.com> | 2010-07-09 18:06:38 -0700 |
commit | a07bbe2e711ee22a40e147c046997c8813ae3cc8 (patch) | |
tree | d4a25fff2328eceaf6b9afe8fcbf4192813f54b2 /lib/puppet/indirector | |
parent | 07b15bf6fa2a2183f73fcb9b6740c7df75c8b47b (diff) | |
download | puppet-a07bbe2e711ee22a40e147c046997c8813ae3cc8.tar.gz puppet-a07bbe2e711ee22a40e147c046997c8813ae3cc8.tar.xz puppet-a07bbe2e711ee22a40e147c046997c8813ae3cc8.zip |
Code smell: Omit needless checks on defined
* Replaced 53 occurances of
defined\?\((.+?)\) (?:and|&&) \1( |$)
with
\1\2
In code like:
unless defined? @foo and @foo and bar("baz")
"defined? @foo and @foo" can safely be replaced with "@foo":
unless @foo and bar("baz")
Because:
* Both evaluate to false/nil when @foo is not defined
* Both evaluate to @foo when @foo is defined
3 Examples:
The code:
@sync = Sync.new unless defined?(@sync) and @sync
becomes:
@sync = Sync.new unless @sync
The code:
unless defined?(@content) and @content
becomes:
unless @content
The code:
raise(ArgumentError, "Already handling indirection for #{@indirection.name}; cannot also handle #{indirection}") if defined?(@indirection) and @indirection
becomes:
raise(ArgumentError, "Already handling indirection for #{@indirection.name}; cannot also handle #{indirection}") if @indirection
* Replaced 2 occurances of
defined\?\((.+?)\) (?:and|&&) ! *\1.nil\?
with
!\1.nil?
In code like:
while defined? @foo and ! @foo.nil? ...
"defined? @foo and ! @foo.nil?" can safely be replaced with "! @foo.nil?":
while ! @foo.nil? ...
Because:
* Both evaluate to false/nil when @foo is not defined
* Both evaluate to "! @foo.nil?" when @foo is defined
2 Examples:
The code:
!!(defined?(@value) and ! @value.nil?)
becomes:
!!(!@value.nil?)
The code:
self.init unless defined?(@@state) and ! @@state.nil?
becomes:
self.init unless !@@state.nil?
Diffstat (limited to 'lib/puppet/indirector')
-rw-r--r-- | lib/puppet/indirector/indirection.rb | 2 | ||||
-rw-r--r-- | lib/puppet/indirector/ldap.rb | 2 | ||||
-rw-r--r-- | lib/puppet/indirector/request.rb | 2 |
3 files changed, 3 insertions, 3 deletions
diff --git a/lib/puppet/indirector/indirection.rb b/lib/puppet/indirector/indirection.rb index 89235f356..8eaaf26d6 100644 --- a/lib/puppet/indirector/indirection.rb +++ b/lib/puppet/indirector/indirection.rb @@ -77,7 +77,7 @@ class Puppet::Indirector::Indirection def doc text = "" - text += scrub(@doc) + "\n\n" if defined?(@doc) and @doc + text += scrub(@doc) + "\n\n" if @doc if s = terminus_setting() text += "* **Terminus Setting**: #{terminus_setting}" diff --git a/lib/puppet/indirector/ldap.rb b/lib/puppet/indirector/ldap.rb index 0b95b6ee0..3ccb21d52 100644 --- a/lib/puppet/indirector/ldap.rb +++ b/lib/puppet/indirector/ldap.rb @@ -61,7 +61,7 @@ class Puppet::Indirector::Ldap < Puppet::Indirector::Terminus # Create an ldap connection. def connection - unless defined?(@connection) and @connection + unless @connection raise Puppet::Error, "Could not set up LDAP Connection: Missing ruby/ldap libraries" unless Puppet.features.ldap? begin conn = Puppet::Util::Ldap::Connection.instance diff --git a/lib/puppet/indirector/request.rb b/lib/puppet/indirector/request.rb index 898722fd6..32494e18c 100644 --- a/lib/puppet/indirector/request.rb +++ b/lib/puppet/indirector/request.rb @@ -21,7 +21,7 @@ class Puppet::Indirector::Request end def environment - @environment = Puppet::Node::Environment.new() unless defined?(@environment) and @environment + @environment = Puppet::Node::Environment.new() unless @environment @environment end |