Sha256: ace2169fd14e84ddd9a9e689267ebc39a00ecd9dd19f03e9ac055aed58d945b8
Contents?: true
Size: 1.91 KB
Versions: 8
Compression:
Stored size: 1.91 KB
Contents
class SourceAnnotationExtractor class Annotation < Struct.new(:line, :tag, :text) def to_s(options={}) s = "[%3d] " % line s << "[#{tag}] " if options[:tag] s << text end end def self.enumerate(tag, options={}) extractor = new(tag) extractor.display(extractor.find, options) end attr_reader :tag def initialize(tag) @tag = tag end def find(dirs=%w(lib test)) dirs.inject({}) { |h, dir| h.update(find_in(dir)) } end def find_in(dir) results = {} Dir.glob("#{dir}/*") do |item| next if File.basename(item)[0] == ?. if File.directory?(item) results.update(find_in(item)) elsif item =~ /\.(builder|(r(?:b|xml|js)))$/ results.update(extract_annotations_from(item, /#\s*(#{tag}):?\s*(.*)$/)) elsif item =~ /\.(rhtml|erb)$/ results.update(extract_annotations_from(item, /<%\s*#\s*(#{tag}):?\s*(.*?)\s*%>/)) end end results end def extract_annotations_from(file, pattern) lineno = 0 result = File.readlines(file).inject([]) do |list, line| lineno += 1 next list unless line =~ pattern list << Annotation.new(lineno, $1, $2) end result.empty? ? {} : { file => result } end def display(results, options={}) results.keys.sort.each do |file| puts "#{file}:" results[file].each do |note| puts " * #{note.to_s(options)}" end puts end end end desc "Enumerate all annotations" task :notes do SourceAnnotationExtractor.enumerate "OPTIMIZE|FIXME|TODO", :tag => true end namespace :notes do desc "Enumerate all OPTIMIZE annotations" task :optimize do SourceAnnotationExtractor.enumerate "OPTIMIZE" end desc "Enumerate all FIXME annotations" task :fixme do SourceAnnotationExtractor.enumerate "FIXME" end desc "Enumerate all TODO annotations" task :todo do SourceAnnotationExtractor.enumerate "TODO" end end
Version data entries
8 entries across 8 versions & 1 rubygems