Module: RakeFileUtils

Extended by:
RakeFileUtils
Includes:
FileUtils
Included in:
RakeFileUtils
Defined in:
lib/rake.rb

Overview

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

Constant Summary

Constants included from FileUtils

FileUtils::LN_SUPPORTED, FileUtils::RUBY

Class Attribute Summary collapse

Instance Method Summary collapse

Methods included from FileUtils

#ruby, #safe_ln, #sh, #split_all

Class Attribute Details

.nowrite_flagObject

Returns the value of attribute nowrite_flag.



1049
1050
1051
# File 'lib/rake.rb', line 1049

def nowrite_flag
  @nowrite_flag
end

.verbose_flagObject

Returns the value of attribute verbose_flag.



1049
1050
1051
# File 'lib/rake.rb', line 1049

def verbose_flag
  @verbose_flag
end

Instance Method Details

#nowrite(value = nil) ⇒ Object

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.


1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
# File 'lib/rake.rb', line 1106

def nowrite(value=nil)
  oldvalue = RakeFileUtils.nowrite_flag
  RakeFileUtils.nowrite_flag = value unless value.nil?
  if block_given?
    begin
      yield
    ensure
      RakeFileUtils.nowrite_flag = oldvalue
    end
  end
  oldvalue
end

#verbose(value = nil) ⇒ Object

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.


1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
# File 'lib/rake.rb', line 1085

def verbose(value=nil)
  oldvalue = RakeFileUtils.verbose_flag
  RakeFileUtils.verbose_flag = value unless value.nil?
  if block_given?
    begin
      yield
    ensure
      RakeFileUtils.verbose_flag = oldvalue
    end
  end
  RakeFileUtils.verbose_flag
end

#when_writing(msg = nil) ⇒ Object

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.



1133
1134
1135
1136
1137
1138
1139
# File 'lib/rake.rb', line 1133

def when_writing(msg=nil)
  if RakeFileUtils.nowrite_flag
    puts "DRYRUN: #{msg}" if msg
  else
    yield
  end
end