Module
Rake::FileUtilsExt
In: lib/rake/file_utils_ext.rb

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

Methods

nowrite, rake_check_options, rake_merge_option, rake_output_message, verbose, when_writing,
Attributes

 [RW]  nowrite_flag
 [RW]  verbose_flag
Included modules

FileUtils
Public Instance methods
nowrite(value=nil) {|| ...}

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 70
70:     def nowrite(value=nil)
71:       oldvalue = FileUtilsExt.nowrite_flag
72:       FileUtilsExt.nowrite_flag = value unless value.nil?
73:       if block_given?
74:         begin
75:           yield
76:         ensure
77:           FileUtilsExt.nowrite_flag = oldvalue
78:         end
79:       end
80:       oldvalue
81:     end
rake_check_options(options, *optdecl)

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 122
122:     def rake_check_options(options, *optdecl)
123:       h = options.dup
124:       optdecl.each do |name|
125:         h.delete name
126:       end
127:       raise ArgumentError, "no such option: #{h.keys.join(' ')}" unless h.empty?
128:     end
rake_merge_option(args, defaults)

Merge the given options with the default values.

     # File lib/rake/file_utils_ext.rb, line 106
106:     def rake_merge_option(args, defaults)
107:       if Hash === args.last
108:         defaults.update(args.last)
109:         args.pop
110:       end
111:       args.push defaults
112:       args
113:     end
rake_output_message(message)

Send the message to the default rake output (which is $stderr).

     # File lib/rake/file_utils_ext.rb, line 116
116:     def rake_output_message(message)
117:       $stderr.puts(message)
118:     end
verbose(value=nil) {|| ...}

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 49
49:     def verbose(value=nil)
50:       oldvalue = FileUtilsExt.verbose_flag
51:       FileUtilsExt.verbose_flag = value unless value.nil?
52:       if block_given?
53:         begin
54:           yield
55:         ensure
56:           FileUtilsExt.verbose_flag = oldvalue
57:         end
58:       end
59:       FileUtilsExt.verbose_flag
60:     end
when_writing(msg=nil) {|| ...}

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 97
 97:     def when_writing(msg=nil)
 98:       if FileUtilsExt.nowrite_flag
 99:         puts "DRYRUN: #{msg}" if msg
100:       else
101:         yield
102:       end
103:     end