Permalink
Browse files

Added support to filter files to search by extension

  • Loading branch information...
1 parent 636dcac commit 9bb862025d420fdfbf9a7ff33f296ddbec48dfde @gschammah gschammah committed May 17, 2012
Showing with 15 additions and 13 deletions.
  1. +10 −9 lib/annotations/extractor.rb
  2. +5 −4 lib/annotations/rake_task.rb
@@ -37,14 +37,15 @@ def to_s(options={})
#
# This class method is the single entry point for the rake tasks.
def self.enumerate(tag, options={})
- extractor = new(tag)
+ extractor = new(tag, options)
extractor.display(extractor.find, options)
end
attr_reader :tag
- def initialize(tag)
+ def initialize(tag, options)
@tag = tag
+ @extensions = options[:extensions]
end
# Returns a hash that maps filenames under +dirs+ (recursively) to arrays
@@ -63,13 +64,13 @@ def find(dirs=%w(.))
def find_in(dir)
results = {}
- Dir.glob("#{dir}/*") do |item|
- next if File.basename(item)[0] == ?.
+ pattern = "#{dir}/**/*"
+ pattern += ".{#{@extensions}}" if @extensions
- if File.directory?(item)
- results.update(find_in(item))
- # Ruby source code
- elsif item =~ /\.(ru|builder|coffee|(r(?:b|xml|js)))$/
+ Dir.glob(pattern) do |item|
+ next if File.basename(item)[0] == ?. or File.directory?(item)
+
+ if item =~ /\.(ru|builder|coffee|(r(?:b|xml|js)))$/
results.update(extract_annotations_from(item, /#\s*(#{tag}):?\s*(.*)$/))
# Other Ruby source files (Rake, Bundler)
elsif item =~ /(Rakefile|Gemfile|Guardfile)$/
@@ -111,4 +112,4 @@ def display(results, options={})
end
end
end
-end
+end
@@ -10,6 +10,7 @@ class RakeTask < ::Rake::TaskLib
def initialize(name = :notes)
@name = name
@tags = [:optimize, :fixme, :todo]
+ @extensions = ENV["ext"]
yield self
define
end
@@ -22,24 +23,24 @@ def tags_to_pattern
def define
desc "Enumerate all annotations"
task name do
- Annotations::Extractor.enumerate(tags_to_pattern, :tag => true)
+ Annotations::Extractor.enumerate(tags_to_pattern, :tag => true, :extensions => @extensions)
end
namespace name do
tags.each do |tagname|
desc "Enumerate all #{tagname.to_s.upcase} annotations"
task tagname.to_sym do
- Annotations::Extractor.enumerate(tagname.to_s.upcase, :tag => true)
+ Annotations::Extractor.enumerate(tagname.to_s.upcase, :tag => true, :extensions => @extensions)
end
end
desc "Enumerate a custom annotation, specify with ANNOTATION=CUSTOM"
task :custom, :annotation do |annotation|
puts annotation
- SourceAnnotationExtractor.enumerate ENV['ANNOTATION']
+ Annotations::Extractor.enumerate(ENV['ANNOTATION'], :extensions => @extensions)
end
end
end
end
-end
+end

0 comments on commit 9bb8620

Please sign in to comment.