Class Buildr::Filter
In: lib/buildr/core/filter.rb  (CVS)
Parent: Object

A filter knows how to copy files from one directory to another, applying mappings to the contents of these files.

You can specify the mapping using a Hash, and it will map ${key} fields found in each source file into the appropriate value in the target file. For example:

  filter.using 'version'=>'1.2', 'build'=>Time.now

will replace all occurrences of ${version} with 1.2, and ${build} with the current date/time.

You can also specify the mapping by passing a proc or a method, that will be called for each source file, with the file name and content, returning the modified content.

Without any mapping, the filter simply copies files from the source directory into the target directory.

A filter has one target directory, but you can specify any number of source directories, either when creating the filter or calling from. Include/exclude patterns are specified relative to the source directories, so:

  filter.include '*.png'

will only include PNG files from any of the source directories. In the same way, you can use regular expressions, so:

  filter.include /picture_.*\.png/

will only include PNG files starting with picture_ from any of the sources directories.

See Buildr#filter.

Methods

add   clear   exclude   from   include   into   pattern_match   run   target   to_s   using  

Classes and Modules

Class Buildr::Filter::Mapper

Attributes

sources  [R]  Returns the list of source directories (each being a file task).

Public Instance methods

add(*files)

Alias for include

Clear filter sources and include/exclude patterns

Specifies files to exclude and returns self. See FileList#exclude.

Adds additional directories from which to copy resources.

For example:

  filter.from('src').into('target').using('build'=>Time.now)

Specifies files to include and returns self. See FileList#include.

By default all files are included. You can use this method to only include specific files from the source directory.

Sets the target directory into which files are copied and returns self.

For example:

  filter.from('src').into('target').using('build'=>Time.now)

Runs the filter.

The target directory as a file task.

Returns the target directory.

Specifies the mapping to use and returns self.

The most typical mapping uses a Hash, and the default mapping uses the Maven style, so ${key} are mapped to the values. You can change that by passing a different format as the first argument. Currently supports:

  • :ant — Map @key@.
  • :maven — Map ${key} (default).
  • :ruby — Map #{key}.
  • :erb — Map <%= key %>.
  • Regexp — Maps the matched data (e.g. /=(.*?)=/

For example:

  filter.using 'version'=>'1.2'

Is the same as:

  filter.using :maven, 'version'=>'1.2'

You can also pass a proc or method. It will be called with the file name and content, to return the mapped content.

Without any mapping, all files are copied as is.

To register new mapping type see the Mapper class.

Protected Instance methods

This method returns true if the file name matches the pattern. The pattern may be a String, a Regexp or a Proc.

[Validate]