From 7fff04f4e8a5fcb8081adeeb81bbd7f866ac07ee Mon Sep 17 00:00:00 2001 From: "Brian D. Burns" Date: Tue, 15 Jan 2013 13:47:12 -0500 Subject: use case statement --- railties/lib/rails/source_annotation_extractor.rb | 26 ++++++++++++++--------- 1 file changed, 16 insertions(+), 10 deletions(-) (limited to 'railties/lib/rails/source_annotation_extractor.rb') diff --git a/railties/lib/rails/source_annotation_extractor.rb b/railties/lib/rails/source_annotation_extractor.rb index 971fbf627b..0a352f1a18 100644 --- a/railties/lib/rails/source_annotation_extractor.rb +++ b/railties/lib/rails/source_annotation_extractor.rb @@ -68,16 +68,22 @@ class SourceAnnotationExtractor if File.directory?(item) results.update(find_in(item)) - elsif item =~ /\.(builder|rb|coffee|rake)$/ - results.update(extract_annotations_from(item, /#\s*(#{tag}):?\s*(.*)$/)) - elsif item =~ /\.(css|scss|js)$/ - results.update(extract_annotations_from(item, /\/\/\s*(#{tag}):?\s*(.*)$/)) - elsif item =~ /\.erb$/ - results.update(extract_annotations_from(item, /<%\s*#\s*(#{tag}):?\s*(.*?)\s*%>/)) - elsif item =~ /\.haml$/ - results.update(extract_annotations_from(item, /-\s*#\s*(#{tag}):?\s*(.*)$/)) - elsif item =~ /\.slim$/ - results.update(extract_annotations_from(item, /\/\s*\s*(#{tag}):?\s*(.*)$/)) + else + pattern = + case item + when /\.(builder|rb|coffee|rake)$/ + /#\s*(#{tag}):?\s*(.*)$/ + when /\.(css|scss|js)$/ + /\/\/\s*(#{tag}):?\s*(.*)$/ + when /\.erb$/ + /<%\s*#\s*(#{tag}):?\s*(.*?)\s*%>/ + when /\.haml$/ + /-\s*#\s*(#{tag}):?\s*(.*)$/ + when /\.slim$/ + /\/\s*\s*(#{tag}):?\s*(.*)$/ + else nil + end + results.update(extract_annotations_from(item, pattern)) if pattern end end -- cgit v1.2.3 From 5a9b3b7a74e5b284312d69c8fd7a6fd3167f6dad Mon Sep 17 00:00:00 2001 From: "Brian D. Burns" Date: Tue, 15 Jan 2013 13:56:10 -0500 Subject: allow :dirs option for .enumerate Allows custom rake tasks to be defined using: SourceAnnotationExtractor.enumerate 'TODO|FIXME', dirs: %w(app lib), tag: true --- railties/lib/rails/source_annotation_extractor.rb | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) (limited to 'railties/lib/rails/source_annotation_extractor.rb') diff --git a/railties/lib/rails/source_annotation_extractor.rb b/railties/lib/rails/source_annotation_extractor.rb index 0a352f1a18..2cbb0a435c 100644 --- a/railties/lib/rails/source_annotation_extractor.rb +++ b/railties/lib/rails/source_annotation_extractor.rb @@ -32,15 +32,24 @@ class SourceAnnotationExtractor end # Prints all annotations with tag +tag+ under the root directories +app+, - # +config+, +lib+, and +test+ (recursively). Filenames with extension - # +.builder+, +.rb+, +.erb+, +.haml+, +.slim+, +.css+, +.scss+, +.js+, - # +.coffee+, and +.rake+ are taken into account. The +options+ hash is - # passed to each annotation's +to_s+. + # +config+, +db+, +lib+, and +test+ (recursively). + # + # Additional directories may be added using a comma-delimited list set using + # ENV['SOURCE_ANNOTATION_DIRECTORIES']. + # + # Directories may also be explicitly set using the :dirs key in +options+. + # + # SourceAnnotationExtractor.enumerate 'TODO|FIXME', dirs: %w(app lib), tag: true + # + # If +options+ has a :tag flag, it will be passed to each annotation's +to_s+. + # + # See #find_in for a list of file extensions that will be taken into account. # # This class method is the single entry point for the rake tasks. def self.enumerate(tag, options={}) extractor = new(tag) - extractor.display(extractor.find, options) + dirs = options.delete(:dirs) || Annotation.directories + extractor.display(extractor.find(dirs), options) end attr_reader :tag @@ -51,7 +60,7 @@ class SourceAnnotationExtractor # Returns a hash that maps filenames under +dirs+ (recursively) to arrays # with their annotations. - def find(dirs = Annotation.directories) + def find(dirs) dirs.inject({}) { |h, dir| h.update(find_in(dir)) } end -- cgit v1.2.3