class Rufo::FileList


list of file names.
FileList/Array is requested, the pending patterns are resolved into a real
actually used. The key is that the first time an element of the
files, but only search out the actual files when then FileList itself is
This allows us to define a number of FileList to match any number of
to find the files, a FileList holds the pattern for latter use.
to be included in the file list, instead of searching the file structures
FileLists are lazy. When given a list of glob patterns for possible files
make file manipulation a bit easier.
A FileList is essentially an array with a few helper methods defined to
#

def <<(obj)

def <<(obj)
  resolve
  @items << obj
  self
end

def add_matching(pattern)

Add matching glob patterns.
def add_matching(pattern)
  self.class.glob(pattern).each do |fn|
    self << fn unless excluded_from_list?(fn)
  end
end

def exclude(*patterns, &block)


FileList['a.c', 'b.c'].exclude("a.*") => ['a.c', 'b.c']
If "a.c" is not a file, then ...

FileList['a.c', 'b.c'].exclude("a.*") => ['b.c']
If "a.c" is a file, then ...

FileList['a.c', 'b.c'].exclude(/^a/) => ['b.c']
FileList['a.c', 'b.c'].exclude("a.c") => ['b.c']
Examples:

file.
system, then an glob pattern in the exclude list will not exclude the
is explicitly added to a file list, but does not exist in the file
Note that glob patterns are expanded against the file system. If a file

return true when given to the block.
strings. In addition, a block given to exclude will remove entries that
list. Patterns may be regular expressions, glob patterns or regular
Register a list of file name patterns that should be excluded from the
def exclude(*patterns, &block)
  patterns.each do |pat|
    @exclude_patterns << pat
  end
  @exclude_procs << block if block_given?
  resolve_exclude unless @pending
  self
end

def excluded_from_list?(filename)

Should the given file name be excluded from the list?
def excluded_from_list?(filename)
  return true if @exclude_patterns.any? do |pat|
    case pat
    when Regexp
      filename =~ pat
    when GLOB_PATTERN
      flags = File::FNM_PATHNAME
      flags |= File::FNM_EXTGLOB
      File.fnmatch?(pat, filename, flags)
    else
      filename == pat
    end
  end
  @exclude_procs.any? { |p| p.call(filename) }
end

def glob(pattern, *args)

the files returned are guaranteed to be sorted.
should be preferred to Dir[pattern] and Dir.glob(pattern) because
Get a sorted list of files matching the pattern. This method
def glob(pattern, *args)
  Dir.glob(pattern, *args).sort
end

def include(*filenames)


file_list.include %w( math.c lib.h *.o )
file_list.include("*.java", "*.cfg")
Example:

is given, add each element of the array.
Add file names defined by glob patterns to the file list. If an array
def include(*filenames)
  filenames.each do |fn|
    @pending_add << fn
  end
  @pending = true
  self
end

def initialize(*patterns)


end
fl.exclude(/\bCVS\b/)
pkg_files = FileList.new('lib/**/*') do |fl|

file_list = FileList.new('lib/**/*.rb', 'test/test*.rb')
Example:

"yield self" pattern.
perform multiple includes or excludes at object build time, use the
Create a file list from the globbable patterns given. If you wish to
def initialize(*patterns)
  @pending_add = []
  @pending = false
  @exclude_patterns = DEFAULT_IGNORE_PATTERNS.dup
  @exclude_procs = DEFAULT_IGNORE_PROCS.dup
  @items = []
  patterns.each { |pattern| include(pattern) }
  yield self if block_given?
end

def resolve

Resolve all the pending adds now.
def resolve
  if @pending
    @pending = false
    @pending_add.each do |fn| resolve_add(fn) end
    @pending_add = []
    resolve_exclude
  end
  self
end

def resolve_add(filename) # :nodoc:

:nodoc:
def resolve_add(filename) # :nodoc:
  case filename
  when GLOB_PATTERN
    add_matching(filename)
  else
    self << filename
  end
end

def resolve_exclude # :nodoc:

:nodoc:
def resolve_exclude # :nodoc:
  reject! { |fn| excluded_from_list?(fn) }
  self
end

def to_a

Return the internal array object.
def to_a
  resolve
  @items
end

def to_s

Convert a FileList to a string by joining all elements with a space.
def to_s
  resolve
  self.join(" ")
end