Sha256: 722150126c2c55a8326af418db94f6831aa049953f794cfcacafb2cb75ec2ef7

Contents?: true

Size: 1.45 KB

Versions: 1

Compression:

Stored size: 1.45 KB

Contents

#                                                                          
# 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 <andrea.fazzi@alca.le.it> (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

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
dokkit-0.3.0 lib/dokkit/fileselection.rb