-
-
Save jbrains/9451941 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
GFILE = "Gemfile.lock" | |
list = File.read(GFILE) | |
gems = [] | |
list.each_line do |line| | |
line = line.strip | |
break if line.include?("PLATFORMS") | |
next if line.include?("GEM") | |
next if line.include?("remote:") | |
next if line.include?("specs:") | |
next if line.empty? | |
gems.push(line.split(' ').first) | |
end | |
# SMELL Depends on globals like 'puts' and `` (execute process). | |
def count_lines_for_gem(gem) | |
puts "Processing #{gem}" | |
contents = `gem contents #{gem}`.split | |
# REFACTOR Remove duplication between this name and the function's name. | |
line_count_for_this_gem = 0 | |
contents.each do |file| | |
output = `wc -l #{file}` | |
amount = output.strip.split(' ').first.to_i | |
line_count_for_this_gem += amount | |
end | |
puts " LOC: #{line_count_for_this_gem}" | |
return line_count_for_this_gem | |
end | |
total = 0 | |
gems.each do |gem| | |
total += count_lines_for_gem(gem) | |
end | |
puts "Total Lines: #{total}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
If you don't care about the interim line count in each gem, then we can remove the duplicate
count_lines
concept, replacing the whole thing with this, in approximate Haskell, of course: