Created
November 21, 2009 03:49
-
-
Save briandonahue/239981 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'fileutils' | |
require 'Rake' | |
class SmartFileList < Rake::FileList | |
attr_accessor :base_path | |
def initialize(base_path) | |
super() | |
@base_path = base_path.sub(%r{/$}, "") | |
end | |
def extensions(*extensions) | |
puts extensions | |
paths = Array.new | |
extensions.each do |ext| | |
paths << "*.#{ext}" | |
end | |
include(paths) | |
end | |
def include(*filenames) | |
filenames.each do |fn| | |
if fn.respond_to? :to_ary | |
include(*fn.to_ary) | |
else | |
puts "path: #{fn}" | |
new_path = map_on_base_path(fn) | |
puts new_path | |
super new_path | |
end | |
end | |
end | |
private | |
def map_on_base_path(pattern) | |
return "#{@base_path}/**/#{pattern}" | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
list = SmartFileList.new("/my/path") | |
list.extensions("aspx", "etc") | |
list.exclude("obj", "whatever") | |
list.each do |file| | |
do_whatever(file) | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment