Module: RakeFileUtils

Module | RakeFileUtils
In: | lib/rake.rb

########################################################################### RakeFileUtils provides a custom version of the FileUtils methods that respond to the `verbose` and `nowrite` commands.

### Methods

nowrite verbose when_writing

### Included Modules

FileUtils

### Attributes

nowrite_flag | [RW] |
verbose_flag | [RW] |

### Public Instance methods

nowrite(value=nil) {|| ...}

Get/set the nowrite flag controlling output from the FileUtils utilities. If verbose is true, then the utility method is echoed to standard output.

Examples:

       nowrite              # return the current value of the nowrite flag
       nowrite(v)           # set the nowrite flag to _v_.
       nowrite(v) { code }  # Execute code with the nowrite flag set temporarily to _v_.
                            # Return to the original value when code is done.

[Source]

          # File lib/rake.rb, line 1107
    1107:   def nowrite(value=nil)
    1108:     oldvalue = RakeFileUtils.nowrite_flag
    1109:     RakeFileUtils.nowrite_flag = value unless value.nil?
    1110:     if block_given?
    1111:       begin
    1112:         yield
    1113:       ensure
    1114:         RakeFileUtils.nowrite_flag = oldvalue
    1115:       end
    1116:     end
    1117:     oldvalue
    1118:   end

verbose(value=nil) {|| ...}

Get/set the verbose flag controlling output from the FileUtils utilities. If verbose is true, then the utility method is echoed to standard output.

Examples:

       verbose              # return the current value of the verbose flag
       verbose(v)           # set the verbose flag to _v_.
       verbose(v) { code }  # Execute code with the verbose flag set temporarily to _v_.
                            # Return to the original value when code is done.

[Source]

          # File lib/rake.rb, line 1086
    1086:   def verbose(value=nil)
    1087:     oldvalue = RakeFileUtils.verbose_flag
    1088:     RakeFileUtils.verbose_flag = value unless value.nil?
    1089:     if block_given?
    1090:       begin
    1091:         yield
    1092:       ensure
    1093:         RakeFileUtils.verbose_flag = oldvalue
    1094:       end
    1095:     end
    1096:     RakeFileUtils.verbose_flag
    1097:   end

when_writing(msg=nil) {|| ...}

Use this function to prevent protentially destructive ruby code from running when the :nowrite flag is set.

Example:

      when_writing("Building Project") do
        project.build
      end

The following code will build the project under normal conditions. If the nowrite(true) flag is set, then the example will print:

         DRYRUN: Building Project

instead of actually building the project.

[Source]

          # File lib/rake.rb, line 1134
    1134:   def when_writing(msg=nil)
    1135:     if RakeFileUtils.nowrite_flag
    1136:       puts "DRYRUN: #{msg}" if msg
    1137:     else
    1138:       yield
    1139:     end
    1140:   end

[Validate]