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 'mega/filelist'

  fl = FileList.new
  fl.include('./**/*')
  fl.exclude('./*~')
Methods
Constants
DEFAULT_IGNORE_PATTERNS = [ /(^|[\/\\])CVS([\/\\]|$)/, /\.bak$/, /~$/, /(^|[\/\\])core$/
Public Class methods
[](*args) [ source ]

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

  FileList.new(*args)
clear_ignore_patterns() [ source ]

Clear the ignore patterns.

new(*patterns) {|self if block_given?| ...} [ source ]

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
select_default_ignore_patterns() [ source ]

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

calculate_exclude_regexp() [ source ]
clear_exclude() [ source ]
exclude(*patterns) [ source ]

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']
exclude?(fn) [ source ]

Should the given file name be excluded?

gsub(pat, rep) [ source ]

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']
gsub!(pat, rep) [ source ]

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

include(*filenames) [ source ]

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 )
This method is also aliased as add
resolve() [ source ]

Resolve all the pending adds now.

resolve_add(fn) [ source ]
resolve_exclude() [ source ]
sub(pat, rep) [ source ]

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']
sub!(pat, rep) [ source ]

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

to_s() [ source ]

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

to_str() [ source ]

Convert a FileList to a string prior to resolving.