########################################################################### FileUtilsExt provides a custom version of the FileUtils methods that respond to the verbose and nowrite commands.
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.
# File lib/rake/file_utils_ext.rb, line 69
69: def nowrite(value=nil)
70: oldvalue = FileUtilsExt.nowrite_flag
71: FileUtilsExt.nowrite_flag = value unless value.nil?
72: if block_given?
73: begin
74: yield
75: ensure
76: FileUtilsExt.nowrite_flag = oldvalue
77: end
78: end
79: oldvalue
80: end
Check that the options do not contain options not listed in optdecl. An ArgumentError exception is thrown if non-declared options are found.
# File lib/rake/file_utils_ext.rb, line 121
121: def rake_check_options(options, *optdecl)
122: h = options.dup
123: optdecl.each do |name|
124: h.delete name
125: end
126: raise ArgumentError, "no such option: #{h.keys.join(' ')}" unless h.empty?
127: end
Merge the given options with the default values.
# File lib/rake/file_utils_ext.rb, line 105
105: def rake_merge_option(args, defaults)
106: if Hash === args.last
107: defaults.update(args.last)
108: args.pop
109: end
110: args.push defaults
111: args
112: end
Send the message to the default rake output (which is $stderr).
# File lib/rake/file_utils_ext.rb, line 115
115: def rake_output_message(message)
116: $stderr.puts(message)
117: 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.
# File lib/rake/file_utils_ext.rb, line 48
48: def verbose(value=nil)
49: oldvalue = FileUtilsExt.verbose_flag
50: FileUtilsExt.verbose_flag = value unless value.nil?
51: if block_given?
52: begin
53: yield
54: ensure
55: FileUtilsExt.verbose_flag = oldvalue
56: end
57: end
58: FileUtilsExt.verbose_flag
59: 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.
# File lib/rake/file_utils_ext.rb, line 96
96: def when_writing(msg=nil)
97: if FileUtilsExt.nowrite_flag
98: puts "DRYRUN: #{msg}" if msg
99: else
100: yield
101: end
102: end
Disabled; run with --debug to generate this.
Generated with the Darkfish Rdoc Generator 1.1.6.