Module UtilityFunctions
In: utils.rb
Methods
abort    ansiCode    debugMsg    divider    editInPlace    errorMessage    extractNextVersionFromTags    extractProjectName    findCatalogKeyword    findProgram    findRdocCvsURL    findRdocMain    findRdocTitle    findRdocUpload    findRdocableFiles    getVettedManifest    header    message    prompt    promptWithDefault    readManifest    replaceMessage    shellCommand    testForLibrary    testForRequiredLibrary    try    verboseOff    vetManifest    writeLine   
Public Instance methods
ansiCode( *attributes )

Create a string that contains the ANSI codes specified and return it

testForLibrary( library, nicename=nil )

Test for the presence of the specified library, and output a message describing the test using nicename. If nicename is nil, the value in library is used to build a default.

testForRequiredLibrary( library, nicename=nil, raaUrl=nil, downloadUrl=nil, fatal=true )

Test for the presence of the specified library, and output a message describing the problem using nicename. If nicename is nil, the value in library is used to build a default. If raaUrl and/or downloadUrl are specified, they are also use to build a message describing how to find the required library. If fatal is true, a missing library will cause the program to abort.

header( msg )

Output msg as a ANSI-colored program/section header (white on blue).

message( msg )

Output msg to STDERR and flush it.

errorMessage( msg )

Output the specified msg as an ANSI-colored error message (white on red).

debugMsg( msg )

Output the specified msg as an ANSI-colored debugging message (yellow on blue).

replaceMessage( msg )

Erase the previous line (if supported by your terminal) and output the specified msg instead.

divider( length=75 )

Output a divider made up of length hyphen characters.

This method is also aliased as writeLine
writeLine( length=75 )

Alias for divider

abort( msg )

Output the specified msg colored in ANSI red and exit with a status of 1.

prompt( promptString )

Output the specified promptString as a prompt (in green) and return the user’s input with leading and trailing spaces removed.

promptWithDefault( promptString, default )

Prompt the user with the given promptString via prompt, substituting the given default if the user doesn’t input anything.

findProgram( progname )

Search for the program specified by the given progname in the user’s PATH, and return the full path to it, or nil if no such program is in the path.

extractNextVersionFromTags( file )

Using the CVS log for the given file attempt to guess what the next release version might be. This only works if releases are tagged with tags like ‘RELEASE_x_y’.

extractProjectName()

Extract the project name (CVS Repository name) for the given directory.

readManifest( manifestFile="MANIFEST" )

Read the specified manifestFile, which is a text file describing which files to package up for a distribution. The manifest should consist of one or more lines, each containing one filename or shell glob pattern.

vetManifest( filelist, antimanifest=ANITMANIFEST )

Given a filelist like that returned by readManifest, remove the entries therein which match the Regexp objects in the given antimanifest and return the resultant Array.

getVettedManifest( manifestFile="MANIFEST", antimanifest=ANTIMANIFEST )

Combine a call to readManifest with one to vetManifest.

findRdocTitle( catalogFile="docs/CATALOG" )

Given a documentation catalogFile, extract the title, if available, and return it. Otherwise generate a title from the name of the CVS module.

findRdocMain( catalogFile="docs/CATALOG", default="README" )

Given a documentation catalogFile, extract the name of the file to use as the initally displayed page. If extraction fails, the default will be used if it exists. Returns nil if there is no main file to be found.

findRdocUpload( catalogFile="docs/CATALOG" )

Given a documentation catalogFile, extract an upload URL for RDoc.

findRdocCvsURL( catalogFile="docs/CATALOG" )

Given a documentation catalogFile, extract a CVS web frontend URL for RDoc.

findCatalogKeyword( keyword, catalogFile="docs/CATALOG" )

Given a documentation catalogFile, try extracting the given keyword’s value from it. Keywords are lines that look like:

  # <keyword>: <value>

Returns nil if the catalog file was unreadable or didn’t contain the specified keyword.

findRdocableFiles( catalogFile="docs/CATALOG" )

Given a documentation catalogFile, which is in the same format as that described by readManifest, read and expand it, and then return a list of those files which appear to have RDoc documentation in them. If catalogFile is nil or does not exist, the MANIFEST file is used instead.

editInPlace( file ) {|line| ...}

Open a file and filter each of its lines through the given block a line at a time. The return value of the block is used as the new line, or omitted if the block returns nil or false.

shellCommand( *command )

Execute the specified shell command, read the results, and return them. Like a %x{} that returns an Array instead of a String.

verboseOff() {|| ...}

Execute a block with $VERBOSE set to false, restoring it to its previous value before returning.

try( msg, bind=nil ) {|| ...}

Try the specified code block, printing the given