Skip to content

Instantly share code, notes, and snippets.

@schoblaska
Created November 10, 2015 21:33
Show Gist options
  • Save schoblaska/2989a9f5f8fdc1778eec to your computer and use it in GitHub Desktop.
Save schoblaska/2989a9f5f8fdc1778eec to your computer and use it in GitHub Desktop.
require "date"
specs = []
def get_indentation(line)
line.match(/^(\s*)/)[1].length
end
File.open(ENV["FILE"]) do |file|
spec = nil
line_num = 0
while line = file.gets
line_num += 1
if line =~ /\s*it\s["']/
spec = {
name: line.strip,
indentation: get_indentation(line),
start_ln: line_num
}
elsif line =~ /\s*end/ && spec && get_indentation(line) == spec[:indentation]
spec[:end_ln] = line_num
specs << spec
spec = nil
end
end
end
specs.each do |spec|
blame = `git blame #{ENV["FILE"]} -L #{spec[:start_ln]},#{spec[:end_ln]}`
dates = blame.scan(/(\d{4}-\d{2}-\d{2})/).flatten.map { |s| Date.strptime(s, "%Y-%m-%d") }
spec[:last_modified] = dates.max
end
specs.each do |spec|
puts "#{spec[:last_modified].strftime("%Y-%m-%d")}: #{spec[:name]}"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment