#!/usr/bin/env ruby # FixmeFinder is an utility to search FIXME comments in your source code files # Example: # patterns = %w[ app/**/*.rb lib/**/*.rb schemas/**/*.sql ] # finder = FixmeFinder.new(patterns) # finder.find class FixmeFinder # Patterns to look for files (default is ["**/*.rb"] attr_accessor :patterns # Creates a Fixme finder. The pattern can be passed as an argument. def initialize(patterns=nil) @patterns = patterns || ["**/*.rb"] yield self if block_given? end # Find Fixme ocurrences if files. It outputs matches if +verbose+ is true. def find(verbose=true) files =[] files = @patterns.inject([]) {|sum,p| sum += Dir.glob(p)} files.inject(Array.new) do |matches,f| unless File.expand_path(__FILE__) == File.expand_path(f) File.open(f).readlines.each_with_index do |line,i| if /(FIXME):?\s*(.*$)/.match(line) puts "#{f}:#{i+1}: #{$2}" if verbose matches += [{:file => f, :line => i+1, :match => $2}] end end end matches end end end