Trejkaz created BUILDR-698:
------------------------------

             Summary: LinesOfCode example in the docs has an incorrect method 
of summing the lines
                 Key: BUILDR-698
                 URL: https://issues.apache.org/jira/browse/BUILDR-698
             Project: Buildr
          Issue Type: Documentation
            Reporter: Trejkaz
            Priority: Minor


Most people probably wouldn't notice this, but the LinesOfCode example here: 
http://buildr.apache.org/extending.html

Is summing the lines using the following code:

{code}
      lines = task.prerequisites.map { |path|
        Dir["#{path}/**/*"]
      }.flatten.uniq.inject(0) { |total, file|
        total = 0 if total.nil?
        if File.file? file then
          total + File.readlines(file).count
        end
      }
{code}

However, this block returns nil for the non-file case, so the total gets reset 
to 0 every time you hit a directory. What the code should look like is this:

{code}
      lines = task.prerequisites.flat_map { |path|
        Dir["#{path}/**/*"]
      }.uniq.select { |file|
        File.file?(file)
      }.inject(0) { |total, file|
        total + File.readlines(file).count
      }
{code}

I also removed the unnecessary nil check.



--
This message was sent by Atlassian JIRA
(v6.2#6252)

Reply via email to