RakeFileUtils provides a custom version of the FileUtils methods that respond to the verbose and nowrite commands.
| [RW] | nowrite_flag | |
| [RW] | verbose_flag |
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.
[ show source ]
# File lib/rake.rb, line 849
849: def nowrite(value=nil)
850: oldvalue = RakeFileUtils.nowrite_flag
851: RakeFileUtils.nowrite_flag = value unless value.nil?
852: if block_given?
853: begin
854: yield
855: ensure
856: RakeFileUtils.nowrite_flag = oldvalue
857: end
858: end
859: oldvalue
860: end
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.
[ show source ]
# File lib/rake.rb, line 827
827: def verbose(value=nil)
828: oldvalue = RakeFileUtils.verbose_flag
829: RakeFileUtils.verbose_flag = value unless value.nil?
830: if block_given?
831: begin
832: yield
833: ensure
834: RakeFileUtils.verbose_flag = oldvalue
835: end
836: end
837: RakeFileUtils.verbose_flag
838: end
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.
[ show source ]
# File lib/rake.rb, line 876
876: def when_writing(msg=nil)
877: if RakeFileUtils.nowrite_flag
878: puts "DRYRUN: #{msg}" if msg
879: else
880: yield
881: end
882: end