module Rake::FileUtilsExt
FileUtilsExt
provides a custom version of the FileUtils
methods that respond to the verbose
and nowrite
commands.
Attributes
Public Instance Methods
Source
# File lib/rake/file_utils_ext.rb 76 def nowrite(value=nil) 77 oldvalue = FileUtilsExt.nowrite_flag 78 FileUtilsExt.nowrite_flag = value unless value.nil? 79 if block_given? 80 begin 81 yield 82 ensure 83 FileUtilsExt.nowrite_flag = oldvalue 84 end 85 end 86 oldvalue 87 end
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/file_utils_ext.rb 132 def rake_check_options(options, *optdecl) 133 h = options.dup 134 optdecl.each do |name| 135 h.delete name 136 end 137 raise ArgumentError, "no such option: #{h.keys.join(' ')}" unless h.empty? 138 end
Check that the options do not contain options not listed in optdecl
. An ArgumentError exception is thrown if non-declared options are found.
Source
# File lib/rake/file_utils_ext.rb 115 def rake_merge_option(args, defaults) 116 if Hash === args.last 117 defaults.update(args.last) 118 args.pop 119 end 120 args.push defaults 121 args 122 end
Merge the given options with the default values.
Source
# File lib/rake/file_utils_ext.rb 125 def rake_output_message(message) 126 $stderr.puts(message) 127 end
Send the message to the default rake output (which is $stderr).
Source
# File lib/rake/file_utils_ext.rb 52 def verbose(value=nil) 53 oldvalue = FileUtilsExt.verbose_flag 54 FileUtilsExt.verbose_flag = value unless value.nil? 55 if block_given? 56 begin 57 yield 58 ensure 59 FileUtilsExt.verbose_flag = oldvalue 60 end 61 end 62 FileUtilsExt.verbose_flag 63 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.
Source
# File lib/rake/file_utils_ext.rb 106 def when_writing(msg=nil) 107 if FileUtilsExt.nowrite_flag 108 $stderr.puts "DRYRUN: #{msg}" if msg 109 else 110 yield 111 end 112 end
Use this function to prevent potentially 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.