<feed xmlns='http://www.w3.org/2005/Atom'>
<title>puppet.git/test/network/handler, branch ticket/master/8119</title>
<subtitle>Puppet repo</subtitle>
<link rel='alternate' type='text/html' href='https://fedorapeople.org/cgit/ricky/public_git/puppet.git/'/>
<entry>
<title>Remove use of Puppet::Util::Cacher in Puppet::SSL::Host</title>
<updated>2011-07-22T03:10:25+00:00</updated>
<author>
<name>Nick Lewis</name>
<email>nick@puppetlabs.com</email>
</author>
<published>2011-07-21T18:52:50+00:00</published>
<link rel='alternate' type='text/html' href='https://fedorapeople.org/cgit/ricky/public_git/puppet.git/commit/?id=7048b4c4d8c4a8ad45caf6a02b263ac0a9fa333e'/>
<id>7048b4c4d8c4a8ad45caf6a02b263ac0a9fa333e</id>
<content type='text'>
This class was previously using a cached_attr for its 'localhost' attribute,
representing the Puppet::SSL::Host entry corresponding to the cert in
Puppet[:certname]. We now no longer expire this attribute. This has the effect
that a change to certname during the lifetime of an agent will not be reflected
in the certificate it uses. If this behavior is desired, it will need to be
reimplemented another way.

Reviewed-By: Jacob Helwig &lt;jacob@puppetlabs.com&gt;
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
This class was previously using a cached_attr for its 'localhost' attribute,
representing the Puppet::SSL::Host entry corresponding to the cert in
Puppet[:certname]. We now no longer expire this attribute. This has the effect
that a change to certname during the lifetime of an agent will not be reflected
in the certificate it uses. If this behavior is desired, it will need to be
reimplemented another way.

Reviewed-By: Jacob Helwig &lt;jacob@puppetlabs.com&gt;
</pre>
</div>
</content>
</entry>
<entry>
<title>maint: Use expand_path when requiring spec_helper or puppettest</title>
<updated>2010-12-06T20:01:18+00:00</updated>
<author>
<name>Matt Robinson</name>
<email>matt@puppetlabs.com</email>
</author>
<published>2010-12-06T20:01:18+00:00</published>
<link rel='alternate' type='text/html' href='https://fedorapeople.org/cgit/ricky/public_git/puppet.git/commit/?id=626d7564467bdc0e9d2d385e9aa10c539d9ed175'/>
<id>626d7564467bdc0e9d2d385e9aa10c539d9ed175</id>
<content type='text'>
Doing a require to a relative path can cause files to be required more
than once when they're required from different relative paths.  If you
expand the path fully, this won't happen.  Ruby 1.9 also requires that
you use expand_path when doing these requires.

Paired-with: Jesse Wolfe
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
Doing a require to a relative path can cause files to be required more
than once when they're required from different relative paths.  If you
expand the path fully, this won't happen.  Ruby 1.9 also requires that
you use expand_path when doing these requires.

Paired-with: Jesse Wolfe
</pre>
</div>
</content>
</entry>
<entry>
<title>Maint: Modified uses of indirector.save to call the indirection directly.</title>
<updated>2010-11-30T22:39:39+00:00</updated>
<author>
<name>Paul Berry</name>
<email>paul@puppetlabs.com</email>
</author>
<published>2010-11-30T20:06:52+00:00</published>
<link rel='alternate' type='text/html' href='https://fedorapeople.org/cgit/ricky/public_git/puppet.git/commit/?id=0747b58bfef9c6bb5f1f9ac1eb6a7b3955dac2af'/>
<id>0747b58bfef9c6bb5f1f9ac1eb6a7b3955dac2af</id>
<content type='text'>
This change replaces calls to &lt;model object&gt;.save with calls to &lt;model
class&gt;.indirection.save(&lt;model object&gt;).  This makes the use of the
indirector explicit rather than implicit so that it will be easier to
search for all indirector call sites using grep.  This is an
intermediate refactor on the way towards allowing indirector calls to
be explicitly routed to multiple termini.

This patch affects production code.
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
This change replaces calls to &lt;model object&gt;.save with calls to &lt;model
class&gt;.indirection.save(&lt;model object&gt;).  This makes the use of the
indirector explicit rather than implicit so that it will be easier to
search for all indirector call sites using grep.  This is an
intermediate refactor on the way towards allowing indirector calls to
be explicitly routed to multiple termini.

This patch affects production code.
</pre>
</div>
</content>
</entry>
<entry>
<title>Maint: Modified tests of indirector.save to call the indirection directly.</title>
<updated>2010-11-30T22:39:38+00:00</updated>
<author>
<name>Paul Berry</name>
<email>paul@puppetlabs.com</email>
</author>
<published>2010-11-30T20:06:33+00:00</published>
<link rel='alternate' type='text/html' href='https://fedorapeople.org/cgit/ricky/public_git/puppet.git/commit/?id=f77764de3ace7cc880a77466618a5affe1b61a8e'/>
<id>f77764de3ace7cc880a77466618a5affe1b61a8e</id>
<content type='text'>
This change replaces calls to &lt;model object&gt;.save with calls to &lt;model
class&gt;.indirection.save(&lt;model object&gt;).  This makes the use of the
indirector explicit rather than implicit so that it will be easier to
search for all indirector call sites using grep.  This is an
intermediate refactor on the way towards allowing indirector calls to
be explicitly routed to multiple termini.

This patch affects tests only; the next patch will make the
corresponding change to the code.
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
This change replaces calls to &lt;model object&gt;.save with calls to &lt;model
class&gt;.indirection.save(&lt;model object&gt;).  This makes the use of the
indirector explicit rather than implicit so that it will be easier to
search for all indirector call sites using grep.  This is an
intermediate refactor on the way towards allowing indirector calls to
be explicitly routed to multiple termini.

This patch affects tests only; the next patch will make the
corresponding change to the code.
</pre>
</div>
</content>
</entry>
<entry>
<title>Maint: Refactor tests to use &lt;class&gt;.indirection.&lt;method&gt;</title>
<updated>2010-11-29T20:08:19+00:00</updated>
<author>
<name>Paul Berry</name>
<email>paul@puppetlabs.com</email>
</author>
<published>2010-11-29T19:55:00+00:00</published>
<link rel='alternate' type='text/html' href='https://fedorapeople.org/cgit/ricky/public_git/puppet.git/commit/?id=14f8160674628340ccfd79baeb84f66cf1e0398a'/>
<id>14f8160674628340ccfd79baeb84f66cf1e0398a</id>
<content type='text'>
Replaced uses of the find, search, destroy, and expire methods on
model classes with direct calls to the indirection objects.  This
change affects tests only.
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
Replaced uses of the find, search, destroy, and expire methods on
model classes with direct calls to the indirection objects.  This
change affects tests only.
</pre>
</div>
</content>
</entry>
<entry>
<title>Code smell: Two space indentation</title>
<updated>2010-07-10T01:12:17+00:00</updated>
<author>
<name>Markus Roberts</name>
<email>Markus@reality.com</email>
</author>
<published>2010-07-10T01:12:17+00:00</published>
<link rel='alternate' type='text/html' href='https://fedorapeople.org/cgit/ricky/public_git/puppet.git/commit/?id=3180b9d9b2c844dade1d361326600f7001ec66dd'/>
<id>3180b9d9b2c844dade1d361326600f7001ec66dd</id>
<content type='text'>
Replaced 106806 occurances of ^( +)(.*$) with

The ruby community almost universally (i.e. everyone but Luke, Markus, and the other eleven people
who learned ruby in the 1900s) uses two-space indentation.

3 Examples:

    The code:
        end

        # Tell getopt which arguments are valid
        def test_get_getopt_args
            element = Setting.new :name =&gt; "foo", :desc =&gt; "anything", :settings =&gt; Puppet::Util::Settings.new
            assert_equal([["--foo", GetoptLong::REQUIRED_ARGUMENT]], element.getopt_args, "Did not produce appropriate getopt args")

    becomes:
        end

        # Tell getopt which arguments are valid
        def test_get_getopt_args
          element = Setting.new :name =&gt; "foo", :desc =&gt; "anything", :settings =&gt; Puppet::Util::Settings.new
          assert_equal([["--foo", GetoptLong::REQUIRED_ARGUMENT]], element.getopt_args, "Did not produce appropriate getopt args")

    The code:
            assert_equal(str, val)

            assert_instance_of(Float, result)

        end

        # Now test it with a passed object
    becomes:
          assert_equal(str, val)

          assert_instance_of(Float, result)

        end

        # Now test it with a passed object
    The code:
        end

        assert_nothing_raised do
            klass[:Yay] = "boo"
            klass["Cool"] = :yayness
        end

    becomes:
        end

        assert_nothing_raised do
          klass[:Yay] = "boo"
          klass["Cool"] = :yayness
        end
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
Replaced 106806 occurances of ^( +)(.*$) with

The ruby community almost universally (i.e. everyone but Luke, Markus, and the other eleven people
who learned ruby in the 1900s) uses two-space indentation.

3 Examples:

    The code:
        end

        # Tell getopt which arguments are valid
        def test_get_getopt_args
            element = Setting.new :name =&gt; "foo", :desc =&gt; "anything", :settings =&gt; Puppet::Util::Settings.new
            assert_equal([["--foo", GetoptLong::REQUIRED_ARGUMENT]], element.getopt_args, "Did not produce appropriate getopt args")

    becomes:
        end

        # Tell getopt which arguments are valid
        def test_get_getopt_args
          element = Setting.new :name =&gt; "foo", :desc =&gt; "anything", :settings =&gt; Puppet::Util::Settings.new
          assert_equal([["--foo", GetoptLong::REQUIRED_ARGUMENT]], element.getopt_args, "Did not produce appropriate getopt args")

    The code:
            assert_equal(str, val)

            assert_instance_of(Float, result)

        end

        # Now test it with a passed object
    becomes:
          assert_equal(str, val)

          assert_instance_of(Float, result)

        end

        # Now test it with a passed object
    The code:
        end

        assert_nothing_raised do
            klass[:Yay] = "boo"
            klass["Cool"] = :yayness
        end

    becomes:
        end

        assert_nothing_raised do
          klass[:Yay] = "boo"
          klass["Cool"] = :yayness
        end
</pre>
</div>
</content>
</entry>
<entry>
<title>Code smell: Avoid needless decorations</title>
<updated>2010-07-10T01:07:15+00:00</updated>
<author>
<name>Markus Roberts</name>
<email>Markus@reality.com</email>
</author>
<published>2010-07-10T01:07:15+00:00</published>
<link rel='alternate' type='text/html' href='https://fedorapeople.org/cgit/ricky/public_git/puppet.git/commit/?id=543225970225de5697734bfaf0a6eee996802c04'/>
<id>543225970225de5697734bfaf0a6eee996802c04</id>
<content type='text'>
* Replaced 704 occurances of (.*)\b([a-z_]+)\(\) with \1\2

  3 Examples:

      The code:
          ctx = OpenSSL::SSL::SSLContext.new()
      becomes:
          ctx = OpenSSL::SSL::SSLContext.new
      The code:
          skip()
      becomes:
          skip
      The code:
          path = tempfile()
      becomes:
          path = tempfile

* Replaced 31 occurances of ^( *)end *#.* with \1end

  3 Examples:

      The code:

      becomes:

      The code:
          end # Dir.foreach
      becomes:
          end
      The code:
          end # def
      becomes:
          end
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
* Replaced 704 occurances of (.*)\b([a-z_]+)\(\) with \1\2

  3 Examples:

      The code:
          ctx = OpenSSL::SSL::SSLContext.new()
      becomes:
          ctx = OpenSSL::SSL::SSLContext.new
      The code:
          skip()
      becomes:
          skip
      The code:
          path = tempfile()
      becomes:
          path = tempfile

* Replaced 31 occurances of ^( *)end *#.* with \1end

  3 Examples:

      The code:

      becomes:

      The code:
          end # Dir.foreach
      becomes:
          end
      The code:
          end # def
      becomes:
          end
</pre>
</div>
</content>
</entry>
<entry>
<title>Code smell: Avoid explicit returns</title>
<updated>2010-07-10T01:06:33+00:00</updated>
<author>
<name>Markus Roberts</name>
<email>Markus@reality.com</email>
</author>
<published>2010-07-10T01:06:33+00:00</published>
<link rel='alternate' type='text/html' href='https://fedorapeople.org/cgit/ricky/public_git/puppet.git/commit/?id=8d1fbe4586c91682cdda0cb271649e918fd9778b'/>
<id>8d1fbe4586c91682cdda0cb271649e918fd9778b</id>
<content type='text'>
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] &lt;&lt; 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] &lt;&lt; spec
                    break
                end
            end
            filters
        end
    The code:
        def retrieve
            return_value = super
            return_value = return_value[0] if return_value &amp;&amp; return_value.is_a?(Array)

            return return_value
        end
    becomes:
        def retrieve
            return_value = super
            return_value = return_value[0] if return_value &amp;&amp; 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
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
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] &lt;&lt; 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] &lt;&lt; spec
                    break
                end
            end
            filters
        end
    The code:
        def retrieve
            return_value = super
            return_value = return_value[0] if return_value &amp;&amp; return_value.is_a?(Array)

            return return_value
        end
    becomes:
        def retrieve
            return_value = super
            return_value = return_value[0] if return_value &amp;&amp; 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
</pre>
</div>
</content>
</entry>
<entry>
<title>Code smell: Booleans are first class values.</title>
<updated>2010-07-10T01:06:12+00:00</updated>
<author>
<name>Markus Roberts</name>
<email>Markus@reality.com</email>
</author>
<published>2010-07-10T01:06:12+00:00</published>
<link rel='alternate' type='text/html' href='https://fedorapeople.org/cgit/ricky/public_git/puppet.git/commit/?id=889158ad57e33df083613d6f7d136b2e11aaa16a'/>
<id>889158ad57e33df083613d6f7d136b2e11aaa16a</id>
<content type='text'>
* Replaced 2 occurances of

      def (.*)
          begin
              (.*) = Integer\((.*)\)
              return \2
          rescue ArgumentError
              \2 = nil
          end
          if \2 = (.*)
              return \2
          else
              return false
          end
      end

  with

  2 Examples:

      The code:
          def validuser?(value)
              begin
                  number = Integer(value)
                  return number
              rescue ArgumentError
                  number = nil
              end
              if number = uid(value)
                  return number
              else
                  return false
              end
          end
      becomes:
          def validuser?(value)
              Integer(value) rescue uid(value) || false
          end
      The code:
          def validgroup?(value)
              begin
                  number = Integer(value)
                  return number
              rescue ArgumentError
                  number = nil
              end
              if number = gid(value)
                  return number
              else
                  return false
              end
          end
      becomes:
          def validgroup?(value)
              Integer(value) rescue gid(value) || false
          end

* Replaced 28 occurances of

      return (.*?) if (.*)
      return (.*)

  with

  3 Examples:

      The code:
          return send(options[:mode]) if [:rdoc, :trac, :markdown].include?(options[:mode])
          return other
      becomes:
          return[:rdoc, :trac, :markdown].include?(options[:mode]) ? send(options[:mode]) : other
      The code:
          return true if known_resource_types.definition(name)
          return false
      becomes:
          return(known_resource_types.definition(name) ? true : false)
      The code:
          return :rest if request.protocol == 'https'
          return Puppet::FileBucket::File.indirection.terminus_class
      becomes:
          return(request.protocol == 'https' ? :rest : Puppet::FileBucket::File.indirection.terminus_class)

* Replaced no occurances of

      return (.*?) unless (.*)
      return (.*)

  with

* Replaced 7 occurances of

      if (.*)
          (.*[^:])false
      else
          \2true
      end

  with

  3 Examples:

      The code:
          if RUBY_PLATFORM == "i386-mswin32"
              InstallOptions.ri  = false
          else
              InstallOptions.ri  = true
          end
      becomes:
          InstallOptions.ri  = RUBY_PLATFORM != "i386-mswin32"
      The code:
          if options[:references].length &gt; 1
              with_contents = false
          else
              with_contents = true
          end
      becomes:
          with_contents = options[:references].length &lt;= 1
      The code:
          if value == false or value == "" or value == :undef
              return false
          else
              return true
          end
      becomes:
          return (value != false and value != "" and value != :undef)

* Replaced 19 occurances of

      if (.*)
          (.*[^:])true
      else
          \2false
      end

  with

  3 Examples:

      The code:
          if Puppet::Util::Log.level == :debug
              return true
          else
              return false
          end
      becomes:
          return Puppet::Util::Log.level == :debug
      The code:
          if satisfies?(*features)
              return true
          else
              return false
          end
      becomes:
          return !!satisfies?(*features)
      The code:
          if self.class.parsed_auth_db.has_key?(resource[:name])
              return true
          else
              return false
          end
      becomes:
          return !!self.class.parsed_auth_db.has_key?(resource[:name])

* Replaced 1 occurance of

      if ([a-z_]) = (.*)
          (.*[^:])\1
      else
          \3(.*)
      end

  with

  1 Example:

      The code:
          if c = self.send(@subclassname, method)
              return c
          else
              return nil
          end
      becomes:
          return self.send(@subclassname, method) || nil

* Replaced 2 occurances of

      if (.*)
          (.*[^:])\1
      else
          \2false
      end

  with

  2 Examples:

      The code:
          if hash[:Local]
              @local = hash[:Local]
          else
              @local = false
          end
      becomes:
          @local = hash[:Local]
      The code:
          if hash[:Local]
              @local = hash[:Local]
          else
              @local = false
          end
      becomes:
          @local = hash[:Local]

* Replaced 10 occurances of

      if (.*)
          (.*[^:])(.*)
      else
          \2false
      end

  with

  3 Examples:

      The code:
          if defined?(@isnamevar)
              return @isnamevar
          else
              return false
          end
      becomes:
          return defined?(@isnamevar) &amp;&amp; @isnamevar
      The code:
          if defined?(@required)
              return @required
          else
              return false
          end
      becomes:
          return defined?(@required) &amp;&amp; @required
      The code:
          if number = uid(value)
              return number
          else
              return false
          end
      becomes:
          return (number = uid(value)) &amp;&amp; number

* Replaced no occurances of

      if (.*)
          (.*[^:])nil
      else
          \2(true)
      end

  with

* Replaced no occurances of

      if (.*)
          (.*[^:])true
      else
          \2nil
      end

  with

* Replaced no occurances of

      if (.*)
          (.*[^:])\1
      else
          \2nil
      end

  with

* Replaced 23 occurances of

      if (.*)
          (.*[^:])(.*)
      else
          \2nil
      end

  with

  3 Examples:

      The code:
          if node = Puppet::Node.find(hostname)
              env = node.environment
          else
              env = nil
          end
      becomes:
          env = (node = Puppet::Node.find(hostname)) ? node.environment : nil
      The code:
          if mod = Puppet::Node::Environment.new(env).module(module_name) and mod.files?
              return @mounts[MODULES].copy(mod.name, mod.file_directory)
          else
              return nil
          end
      becomes:
          return (mod = Puppet::Node::Environment.new(env).module(module_name) and mod.files?) ? @mounts[MODULES].copy(mod.name, mod.file_directory) : nil
      The code:
          if hash.include?(:CA) and hash[:CA]
              @ca = Puppet::SSLCertificates::CA.new()
          else
              @ca = nil
          end
      becomes:
          @ca = (hash.include?(:CA) and hash[:CA]) ? Puppet::SSLCertificates::CA.new() : nil
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
* Replaced 2 occurances of

      def (.*)
          begin
              (.*) = Integer\((.*)\)
              return \2
          rescue ArgumentError
              \2 = nil
          end
          if \2 = (.*)
              return \2
          else
              return false
          end
      end

  with

  2 Examples:

      The code:
          def validuser?(value)
              begin
                  number = Integer(value)
                  return number
              rescue ArgumentError
                  number = nil
              end
              if number = uid(value)
                  return number
              else
                  return false
              end
          end
      becomes:
          def validuser?(value)
              Integer(value) rescue uid(value) || false
          end
      The code:
          def validgroup?(value)
              begin
                  number = Integer(value)
                  return number
              rescue ArgumentError
                  number = nil
              end
              if number = gid(value)
                  return number
              else
                  return false
              end
          end
      becomes:
          def validgroup?(value)
              Integer(value) rescue gid(value) || false
          end

* Replaced 28 occurances of

      return (.*?) if (.*)
      return (.*)

  with

  3 Examples:

      The code:
          return send(options[:mode]) if [:rdoc, :trac, :markdown].include?(options[:mode])
          return other
      becomes:
          return[:rdoc, :trac, :markdown].include?(options[:mode]) ? send(options[:mode]) : other
      The code:
          return true if known_resource_types.definition(name)
          return false
      becomes:
          return(known_resource_types.definition(name) ? true : false)
      The code:
          return :rest if request.protocol == 'https'
          return Puppet::FileBucket::File.indirection.terminus_class
      becomes:
          return(request.protocol == 'https' ? :rest : Puppet::FileBucket::File.indirection.terminus_class)

* Replaced no occurances of

      return (.*?) unless (.*)
      return (.*)

  with

* Replaced 7 occurances of

      if (.*)
          (.*[^:])false
      else
          \2true
      end

  with

  3 Examples:

      The code:
          if RUBY_PLATFORM == "i386-mswin32"
              InstallOptions.ri  = false
          else
              InstallOptions.ri  = true
          end
      becomes:
          InstallOptions.ri  = RUBY_PLATFORM != "i386-mswin32"
      The code:
          if options[:references].length &gt; 1
              with_contents = false
          else
              with_contents = true
          end
      becomes:
          with_contents = options[:references].length &lt;= 1
      The code:
          if value == false or value == "" or value == :undef
              return false
          else
              return true
          end
      becomes:
          return (value != false and value != "" and value != :undef)

* Replaced 19 occurances of

      if (.*)
          (.*[^:])true
      else
          \2false
      end

  with

  3 Examples:

      The code:
          if Puppet::Util::Log.level == :debug
              return true
          else
              return false
          end
      becomes:
          return Puppet::Util::Log.level == :debug
      The code:
          if satisfies?(*features)
              return true
          else
              return false
          end
      becomes:
          return !!satisfies?(*features)
      The code:
          if self.class.parsed_auth_db.has_key?(resource[:name])
              return true
          else
              return false
          end
      becomes:
          return !!self.class.parsed_auth_db.has_key?(resource[:name])

* Replaced 1 occurance of

      if ([a-z_]) = (.*)
          (.*[^:])\1
      else
          \3(.*)
      end

  with

  1 Example:

      The code:
          if c = self.send(@subclassname, method)
              return c
          else
              return nil
          end
      becomes:
          return self.send(@subclassname, method) || nil

* Replaced 2 occurances of

      if (.*)
          (.*[^:])\1
      else
          \2false
      end

  with

  2 Examples:

      The code:
          if hash[:Local]
              @local = hash[:Local]
          else
              @local = false
          end
      becomes:
          @local = hash[:Local]
      The code:
          if hash[:Local]
              @local = hash[:Local]
          else
              @local = false
          end
      becomes:
          @local = hash[:Local]

* Replaced 10 occurances of

      if (.*)
          (.*[^:])(.*)
      else
          \2false
      end

  with

  3 Examples:

      The code:
          if defined?(@isnamevar)
              return @isnamevar
          else
              return false
          end
      becomes:
          return defined?(@isnamevar) &amp;&amp; @isnamevar
      The code:
          if defined?(@required)
              return @required
          else
              return false
          end
      becomes:
          return defined?(@required) &amp;&amp; @required
      The code:
          if number = uid(value)
              return number
          else
              return false
          end
      becomes:
          return (number = uid(value)) &amp;&amp; number

* Replaced no occurances of

      if (.*)
          (.*[^:])nil
      else
          \2(true)
      end

  with

* Replaced no occurances of

      if (.*)
          (.*[^:])true
      else
          \2nil
      end

  with

* Replaced no occurances of

      if (.*)
          (.*[^:])\1
      else
          \2nil
      end

  with

* Replaced 23 occurances of

      if (.*)
          (.*[^:])(.*)
      else
          \2nil
      end

  with

  3 Examples:

      The code:
          if node = Puppet::Node.find(hostname)
              env = node.environment
          else
              env = nil
          end
      becomes:
          env = (node = Puppet::Node.find(hostname)) ? node.environment : nil
      The code:
          if mod = Puppet::Node::Environment.new(env).module(module_name) and mod.files?
              return @mounts[MODULES].copy(mod.name, mod.file_directory)
          else
              return nil
          end
      becomes:
          return (mod = Puppet::Node::Environment.new(env).module(module_name) and mod.files?) ? @mounts[MODULES].copy(mod.name, mod.file_directory) : nil
      The code:
          if hash.include?(:CA) and hash[:CA]
              @ca = Puppet::SSLCertificates::CA.new()
          else
              @ca = nil
          end
      becomes:
          @ca = (hash.include?(:CA) and hash[:CA]) ? Puppet::SSLCertificates::CA.new() : nil
</pre>
</div>
</content>
</entry>
<entry>
<title>Code smell: Line modifiers are preferred to one-line blocks.</title>
<updated>2010-07-10T01:06:06+00:00</updated>
<author>
<name>Markus Roberts</name>
<email>Markus@reality.com</email>
</author>
<published>2010-07-10T01:06:06+00:00</published>
<link rel='alternate' type='text/html' href='https://fedorapeople.org/cgit/ricky/public_git/puppet.git/commit/?id=81e283b28cdd91d259e3b60687aee7ea66e9d05d'/>
<id>81e283b28cdd91d259e3b60687aee7ea66e9d05d</id>
<content type='text'>
* Replaced 6 occurances of (while .*?) *do$ with

  The do is unneeded in the block header form and causes problems
  with the block-to-one-line transformation.

  3 Examples:

      The code:
          while line = f.gets do
      becomes:
          while line = f.gets
      The code:
          while line = shadow.gets do
      becomes:
          while line = shadow.gets
      The code:
          while wrapper = zeros.pop do
      becomes:
          while wrapper = zeros.pop

* Replaced 19 occurances of ((if|unless) .*?) *then$ with

  The then is unneeded in the block header form and causes problems
  with the block-to-one-line transformation.

  3 Examples:

      The code:
          if f = test_files_for(failed).find { |f| failed_trace =~ Regexp.new(f) } then
      becomes:
          if f = test_files_for(failed).find { |f| failed_trace =~ Regexp.new(f) }
      The code:
          unless defined?(@spec_command) then
      becomes:
          unless defined?(@spec_command)
      The code:
          if c == ?\n then
      becomes:
          if c == ?\n

* Replaced 758 occurances of

      ((?:if|unless|while|until) .*)
          (.*)
      end

  with

  The one-line form is preferable provided:

      * The condition is not used to assign a variable
      * The body line is not already modified
      * The resulting line is not too long

  3 Examples:

      The code:
          if Puppet.features.libshadow?
              has_feature :manages_passwords
          end
      becomes:
          has_feature :manages_passwords if Puppet.features.libshadow?
      The code:
          unless (defined?(@current_pool) and @current_pool)
              @current_pool = process_zpool_data(get_pool_data)
          end
      becomes:
          @current_pool = process_zpool_data(get_pool_data) unless (defined?(@current_pool) and @current_pool)
      The code:
          if Puppet[:trace]
              puts detail.backtrace
          end
      becomes:
          puts detail.backtrace if Puppet[:trace]
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
* Replaced 6 occurances of (while .*?) *do$ with

  The do is unneeded in the block header form and causes problems
  with the block-to-one-line transformation.

  3 Examples:

      The code:
          while line = f.gets do
      becomes:
          while line = f.gets
      The code:
          while line = shadow.gets do
      becomes:
          while line = shadow.gets
      The code:
          while wrapper = zeros.pop do
      becomes:
          while wrapper = zeros.pop

* Replaced 19 occurances of ((if|unless) .*?) *then$ with

  The then is unneeded in the block header form and causes problems
  with the block-to-one-line transformation.

  3 Examples:

      The code:
          if f = test_files_for(failed).find { |f| failed_trace =~ Regexp.new(f) } then
      becomes:
          if f = test_files_for(failed).find { |f| failed_trace =~ Regexp.new(f) }
      The code:
          unless defined?(@spec_command) then
      becomes:
          unless defined?(@spec_command)
      The code:
          if c == ?\n then
      becomes:
          if c == ?\n

* Replaced 758 occurances of

      ((?:if|unless|while|until) .*)
          (.*)
      end

  with

  The one-line form is preferable provided:

      * The condition is not used to assign a variable
      * The body line is not already modified
      * The resulting line is not too long

  3 Examples:

      The code:
          if Puppet.features.libshadow?
              has_feature :manages_passwords
          end
      becomes:
          has_feature :manages_passwords if Puppet.features.libshadow?
      The code:
          unless (defined?(@current_pool) and @current_pool)
              @current_pool = process_zpool_data(get_pool_data)
          end
      becomes:
          @current_pool = process_zpool_data(get_pool_data) unless (defined?(@current_pool) and @current_pool)
      The code:
          if Puppet[:trace]
              puts detail.backtrace
          end
      becomes:
          puts detail.backtrace if Puppet[:trace]
</pre>
</div>
</content>
</entry>
</feed>
