Skip to content

Instantly share code, notes, and snippets.

@briandonahue
Created November 21, 2009 03:49
Show Gist options
  • Save briandonahue/239981 to your computer and use it in GitHub Desktop.
Save briandonahue/239981 to your computer and use it in GitHub Desktop.
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
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