Class FileList
In: lib/facet/filelist.rb
Parent: Array

Description

A FileList is essentially an array with a few helper methods defined to make file manipulation a bit easier. It works in a fashion similar to Dir.glob.

Synopsis

  require 'trix/filelist'

  fl = FileList.new
  fl.include('./**/*')
  fl.exclude('./*~')

Methods

Constants

VERSION = '1.0.0'
DEFAULT_IGNORE_PATTERNS = [ /(^|[\/\\])CVS([\/\\]|$)/, /\.bak$/, /~$/, /(^|[\/\\])core$/

Public Class methods

Create a new file list including the files listed. Similar to:

  FileList.new(*args)

Clear the ignore patterns.

Create a file list from the globbable patterns given. If you wish to perform multiple includes or excludes at object build time, use the "yield self" pattern.

Example:

  file_list = FileList.new['lib/**/*.rb', 'test/test*.rb']

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

Set the ignore patterns back to the default value. The default patterns will ignore files

  • containing "CVS" in the file path
  • ending with ".bak"
  • ending with "~"
  • named "core"

Note that file names beginning with "." are automatically ignored by Ruby’s glob patterns and are not specifically listed in the ignore patterns.

Public Instance methods

add(*filenames)

Alias for include

Register a list of file name patterns that should be excluded from the list. Patterns may be regular expressions, glob patterns or regular strings.

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

Examples:

  FileList['a.c', 'b.c'].exclude("a.c") => ['b.c']
  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']

If "a.c" is not a file, then …

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

Should the given file name be excluded?

Return a new FileList with the results of running gsub against each element of the original list.

Example:

  FileList['lib/test/file', 'x/y'].gsub(/\//, "\\")
     => ['lib\\test\\file', 'x\\y']

Same as gsub except that the original file list is modified.

Add file names defined by glob patterns to the file list. If an array is given, add each element of the array.

Example:

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

Resolve all the pending adds now.

Return a new FileList with the results of running sub against each element of the oringal list.

Example:

  FileList['a.c', 'b.c'].sub(/\.c$/, '.o')  => ['a.o', 'b.o']

Same as sub except that the oringal file list is modified.

Convert a FileList to a string by joining all elements with a space.

Convert a FileList to a string prior to resolving.

Private Instance methods

Add matching glob patterns.

[Validate]