# # File 'fileselection.rb' created on 07 feb 2008 at 15:52:42. # # See 'dokkit.rb' or +LICENSE+ for licence information. # # (C) 2006, 2007 Andrea Fazzi (and contributors). # require 'rake' module Dokkit module ExtMapping attr_reader :extmapping def extend(regexp=/.*/, &blk) @extmapping ||= { } (files.select { |file| file =~ regexp }).each do |file| @extmapping[file] = blk end end end class FileSelection attr_accessor :base_dir alias :dir :base_dir alias :dir= :base_dir= def initialize(base_dir = '.') @base_dir = base_dir @includes = [] @excludes = [] yield self if block_given? end def include(*patterns) patterns.each { |pattern| @includes << pattern } end def exclude(*patterns) patterns.each { |pattern| @excludes << pattern } end def files FileList.new(@base_dir) do |fl| fl.exclude *@excludes.collect { |exclude| File.join(@base_dir, exclude) } unless @excludes.empty? fl.include *@includes.collect { |include| File.join(@base_dir, include) } unless @includes.empty? end.uniq.select { |fn| not File.directory?(fn) } end end end