module RakeFileUtils
def nowrite(value=nil)
nowrite(v) { code } # Execute code with the nowrite flag set temporarily to _v_.
nowrite(v) # set the nowrite flag to _v_.
nowrite # return the current value of the nowrite flag
Examples:
If verbose is true, then the utility method is echoed to standard output.
Get/set the nowrite flag controlling output from the FileUtils utilities.
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
def rake_check_options(options, *optdecl)
Check that the options do not contain options not listed in +optdecl+. An
def rake_check_options(options, *optdecl) h = options.dup optdecl.each do |name| h.delete name end raise ArgumentError, "no such option: #{h.keys.join(' ')}" unless h.empty? end
def rake_merge_option(args, defaults)
def rake_merge_option(args, defaults) if Hash === args.last defaults.update(args.last) args.pop end args.push defaults args end
def rake_output_message(message)
def rake_output_message(message) $stderr.puts(message) end
def verbose(value=nil)
verbose(v) { code } # Execute code with the verbose flag set temporarily to _v_.
verbose(v) # set the verbose flag to _v_.
verbose # return the current value of the verbose flag
Examples:
If verbose is true, then the utility method is echoed to standard output.
Get/set the verbose flag controlling output from the FileUtils utilities.
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
def when_writing(msg=nil)
instead of actually building the project.
DRYRUN: Building Project
nowrite(true) flag is set, then the example will print:
The following code will build the project under normal conditions. If the
end
project.build
when_writing("Building Project") do
Example:
running when the :nowrite flag is set.
Use this function to prevent protentially destructive ruby code from
def when_writing(msg=nil) if RakeFileUtils.nowrite_flag puts "DRYRUN: #{msg}" if msg else yield end end