Revisions
-
jbrains revised this gist
Mar 9, 2014 . 1 changed file with 3 additions and 2 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -44,6 +44,7 @@ def count_lines_for_gem(gem) return line_count_for_this_gem end total = extract_gems_from_gemfile_lock_file(File.read("Gemfile.lock")) .map { |each| count_lines_for_gem(each) }.reduce(:+) puts "Total Lines: #{total}" -
jbrains revised this gist
Mar 9, 2014 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -30,7 +30,7 @@ def count_lines_in_file(file) # We could turn this comment into code by matching with a regex, which some # would find clearer and others less clear. I could do either. line_count_text = output.strip.split(' ').first return line_count_text.to_i end # SMELL Depends on globals like 'puts' and `` (execute process). -
jbrains revised this gist
Mar 9, 2014 . 1 changed file with 2 additions and 2 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -36,10 +36,10 @@ def count_lines_in_file(file) # SMELL Depends on globals like 'puts' and `` (execute process). def count_lines_for_gem(gem) puts "Processing #{gem}" gem_filenames = `gem contents #{gem}`.split # If you prefer to 'inject', then feel free to 'inject'. # Either way, the name duplication disappears. line_count_for_this_gem = gem_filenames.map { |each| count_lines_in_file(each) }.reduce(:+) puts " LOC: #{line_count_for_this_gem}" return line_count_for_this_gem end -
jbrains revised this gist
Mar 9, 2014 . 1 changed file with 1 addition and 0 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -2,6 +2,7 @@ # what else to call it. I want to distinguish it from Gemfile. def extract_gems_from_gemfile_lock_file(contents) gems = [] # Extract all the non-empty lines between and excluding 'specs:' and 'PLATFORMS' contents.each_line do |line| line = line.strip # It takes a few seconds to understand this algorithm, -
jbrains revised this gist
Mar 9, 2014 . 1 changed file with 2 additions and 2 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1,8 +1,8 @@ # SMELL I don't like the name gemfile_lock_file, but I don't know # what else to call it. I want to distinguish it from Gemfile. def extract_gems_from_gemfile_lock_file(contents) gems = [] contents.each_line do |line| line = line.strip # It takes a few seconds to understand this algorithm, # but I can't yet justify replacing it with a functional -
jbrains revised this gist
Mar 9, 2014 . 1 changed file with 2 additions and 2 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1,6 +1,6 @@ # SMELL I don't like the name gemfile_lock_file, but I don't know # what else to call it. I want to distinguish it from Gemfile. def extract_gems_from_gemfile_lock_file(gemfile_lock_file) gems = [] gemfile_lock_file.each_line do |line| line = line.strip @@ -43,6 +43,6 @@ def count_lines_for_gem(gem) return line_count_for_this_gem end gems = extract_gems_from_gemfile_lock_file(File.read("Gemfile.lock")) total = gems.map { |each| count_lines_for_gem(each) }.reduce(:+) puts "Total Lines: #{total}" -
jbrains revised this gist
Mar 9, 2014 . 1 changed file with 1 addition and 2 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -43,7 +43,6 @@ def count_lines_for_gem(gem) return line_count_for_this_gem end gems = extract_gems_from_gemfile(File.read("Gemfile.lock")) total = gems.map { |each| count_lines_for_gem(each) }.reduce(:+) puts "Total Lines: #{total}" -
jbrains revised this gist
Mar 9, 2014 . 1 changed file with 2 additions and 4 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1,5 +1,3 @@ # SMELL I don't like the name gemfile_lock_file, but I don't know # what else to call it. I want to distinguish it from Gemfile. def extract_gems_from_gemfile(gemfile_lock_file) @@ -23,8 +21,6 @@ def extract_gems_from_gemfile(gemfile_lock_file) return gems end # Guess what? Now independent of "gem" concept. More reusable. MAGIC! # Guess what? Almost dead-simple wrapper around command line tool. Cohesive. SRP. Nice. def count_lines_in_file(file) @@ -47,5 +43,7 @@ def count_lines_for_gem(gem) return line_count_for_this_gem end gemfile_lock_file = File.read("Gemfile.lock") gems = extract_gems_from_gemfile(gemfile_lock_file) total = gems.map { |each| count_lines_for_gem(each) }.reduce(:+) puts "Total Lines: #{total}" -
jbrains revised this gist
Mar 9, 2014 . 1 changed file with 6 additions and 6 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1,10 +1,10 @@ gemfile_lock_file = File.read("Gemfile.lock") # SMELL I don't like the name gemfile_lock_file, but I don't know # what else to call it. I want to distinguish it from Gemfile. def extract_gems_from_gemfile(gemfile_lock_file) gems = [] gemfile_lock_file.each_line do |line| line = line.strip # It takes a few seconds to understand this algorithm, # but I can't yet justify replacing it with a functional @@ -23,7 +23,7 @@ def extract_gems_from_gemfile(list) return gems end gems = extract_gems_from_gemfile(gemfile_lock_file) # Guess what? Now independent of "gem" concept. More reusable. MAGIC! # Guess what? Almost dead-simple wrapper around command line tool. Cohesive. SRP. Nice. -
jbrains revised this gist
Mar 9, 2014 . 1 changed file with 9 additions and 0 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1,9 +1,18 @@ list = File.read("Gemfile.lock") # SMELL Now the name 'list' seems really strange. # REFACTOR Rename 'list', since it's not at all a list. def extract_gems_from_gemfile(list) gems = [] list.each_line do |line| line = line.strip # It takes a few seconds to understand this algorithm, # but I can't yet justify replacing it with a functional # approach. Again, it depends what the reader understands # better. # If we're going to let iterating and filtering stay # intertwined like this, I'm glad we've separated it from # the rest of the code. break if line.include?("PLATFORMS") next if line.include?("GEM") next if line.include?("remote:") -
jbrains revised this gist
Mar 9, 2014 . 1 changed file with 14 additions and 10 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1,17 +1,21 @@ list = File.read("Gemfile.lock") def extract_gems_from_gemfile(list) 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 return gems end gems = extract_gems_from_gemfile(list) # Guess what? Now independent of "gem" concept. More reusable. MAGIC! # Guess what? Almost dead-simple wrapper around command line tool. Cohesive. SRP. Nice. def count_lines_in_file(file) -
jbrains revised this gist
Mar 9, 2014 . 1 changed file with 1 addition and 5 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1,8 +1,4 @@ list = File.read("Gemfile.lock") gems = [] -
jbrains revised this gist
Mar 9, 2014 . 1 changed file with 2 additions and 0 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1,3 +1,5 @@ # REFACTOR Inline temporary variable that's not pulling its weight # and whose name I don't particularly like. GFILE = "Gemfile.lock" list = File.read(GFILE) -
jbrains revised this gist
Mar 9, 2014 . 1 changed file with 1 addition and 5 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -36,9 +36,5 @@ def count_lines_for_gem(gem) return line_count_for_this_gem end total = gems.map { |each| count_lines_for_gem(each) }.reduce(:+) puts "Total Lines: #{total}" -
jbrains revised this gist
Mar 9, 2014 . 1 changed file with 5 additions and 5 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -17,12 +17,12 @@ # Guess what? Now independent of "gem" concept. More reusable. MAGIC! # Guess what? Almost dead-simple wrapper around command line tool. Cohesive. SRP. Nice. def count_lines_in_file(file) output = `wc -l #{file}` # ASSERT: output is of the form <whitespace><line count><whitespace><filename> # We could turn this comment into code by matching with a regex, which some # would find clearer and others less clear. I could do either. line_count_text = output.strip.split(' ').first line_count_text.to_i end # SMELL Depends on globals like 'puts' and `` (execute process). -
jbrains revised this gist
Mar 9, 2014 . 1 changed file with 3 additions and 6 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -29,12 +29,9 @@ def count_lines_in_file(file) def count_lines_for_gem(gem) puts "Processing #{gem}" contents = `gem contents #{gem}`.split # If you prefer to 'inject', then feel free to 'inject'. # Either way, the name duplication disappears. line_count_for_this_gem = contents.map { |each| count_lines_in_file(each) }.reduce(:+) puts " LOC: #{line_count_for_this_gem}" return line_count_for_this_gem end -
jbrains revised this gist
Mar 9, 2014 . 1 changed file with 1 addition and 0 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -30,6 +30,7 @@ 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. # REFACTOR Let's reduce, shall we? line_count_for_this_gem = 0 contents.each do |file| line_count_for_this_gem += count_lines_in_file(file) -
jbrains revised this gist
Mar 9, 2014 . 1 changed file with 12 additions and 6 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -14,19 +14,25 @@ gems.push(line.split(' ').first) end # Guess what? Now independent of "gem" concept. More reusable. MAGIC! # Guess what? Almost dead-simple wrapper around command line tool. Cohesive. SRP. Nice. def count_lines_in_file(file) # SMELL 'output' and 'amount' are both purely structural names (don't reveal intent) # SMELL 'output' and 'amount' names don't reflect their relationship to each other # (both related to the same gem file) output = `wc -l #{file}` amount = output.strip.split(' ').first.to_i amount 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| line_count_for_this_gem += count_lines_in_file(file) end puts " LOC: #{line_count_for_this_gem}" return line_count_for_this_gem -
jbrains revised this gist
Mar 9, 2014 . 1 changed file with 3 additions and 0 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -21,6 +21,9 @@ def count_lines_for_gem(gem) # REFACTOR Remove duplication between this name and the function's name. line_count_for_this_gem = 0 contents.each do |file| # SMELL 'output' and 'amount' are both purely structural names (don't reveal intent) # SMELL 'output' and 'amount' names don't reflect their relationship to each other # (both related to the same gem file) output = `wc -l #{file}` amount = output.strip.split(' ').first.to_i line_count_for_this_gem += amount -
jbrains revised this gist
Mar 9, 2014 . 1 changed file with 1 addition and 0 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -18,6 +18,7 @@ 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}` -
jbrains revised this gist
Mar 9, 2014 . 1 changed file with 1 addition and 11 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -30,17 +30,7 @@ def count_lines_for_gem(gem) total = 0 gems.each do |gem| total += count_lines_for_gem(gem) end puts "Total Lines: #{total}" -
jbrains revised this gist
Mar 9, 2014 . 1 changed file with 14 additions and 0 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -14,6 +14,20 @@ 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 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| # REFACTOR Extract this body as a function. -
jbrains revised this gist
Mar 9, 2014 . 1 changed file with 1 addition and 0 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -16,6 +16,7 @@ total = 0 gems.each do |gem| # REFACTOR Extract this body as a function. puts "Processing #{gem}" contents = `gem contents #{gem}`.split line_count_for_this_gem = 0 -
jbrains revised this gist
Mar 9, 2014 . 1 changed file with 4 additions and 5 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -18,15 +18,14 @@ gems.each do |gem| puts "Processing #{gem}" contents = `gem contents #{gem}`.split 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}" total += line_count_for_this_gem end puts "Total Lines: #{total}" -
jbrains revised this gist
Mar 9, 2014 . 1 changed file with 2 additions and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -18,6 +18,7 @@ gems.each do |gem| puts "Processing #{gem}" contents = `gem contents #{gem}`.split # SMELL 'local' is a purely structural name; doesn't reveal any intent. local = 0 contents.each do |file| output = `wc -l #{file}` @@ -28,4 +29,4 @@ total += local end puts "Total Lines: #{total}" -
CoryFoy created this gist
Mar 9, 2014 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,31 @@ 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 total = 0 gems.each do |gem| puts "Processing #{gem}" contents = `gem contents #{gem}`.split local = 0 contents.each do |file| output = `wc -l #{file}` amount = output.strip.split(' ').first.to_i local += amount end puts " LOC: #{local}" total += local end puts "Total Lines: #{total}"