diff options
-rw-r--r-- | ChangeLog | 4 | ||||
-rw-r--r-- | lib/fileutils.rb | 40 |
2 files changed, 35 insertions, 9 deletions
@@ -1,3 +1,7 @@ +Tue Feb 17 01:20:57 2004 Minero Aoki <aamine@loveruby.net> + + * lib/fileutils.rb: new module FileUtils::DryRun. + Mon Feb 16 23:28:14 2004 NAKAMURA, Hiroshi <nakahiro@sarion.co.jp> * lib/csv.rb: document reduction. [ruby-core:02429] diff --git a/lib/fileutils.rb b/lib/fileutils.rb index 149687c44f..c8f29c3d32 100644 --- a/lib/fileutils.rb +++ b/lib/fileutils.rb @@ -824,12 +824,12 @@ module FileUtils # FileUtils. # module Verbose - include FileUtils @fileutils_output = $stderr @fileutils_label = '' @fileutils_verbose = true + @fileutils_nowrite = false FileUtils::OPT_TABLE.each do |name, opts| next unless opts.include?('verbose') @@ -842,38 +842,60 @@ module FileUtils end extend self - end - # # This module has all methods of FileUtils module, but never changes # files/directories. This equates to passing the <tt>:noop</tt> flag to methods in # FileUtils. # module NoWrite - include FileUtils @fileutils_output = $stderr @fileutils_label = '' + @fileutils_verbose = false @fileutils_nowrite = true FileUtils::OPT_TABLE.each do |name, opts| next unless opts.include?('noop') module_eval(<<-EOS, __FILE__, __LINE__ + 1) def #{name}(*args) - unless defined?(@fileutils_nowrite) - @fileutils_nowrite ||= true - end + @fileutils_nowrite = true unless defined?(@fileutils_nowrite) super(*fu_update_option(args, :noop => true)) end EOS end extend self - end -end + # + # This module has all methods of FileUtils module, but never changes + # files/directories, with printing message before acting. + # This equates to passing the +:noop+ and +:verbose+ flag + # to methods in FileUtils. + # + module DryRun + include FileUtils + + @fileutils_output = $stderr + @fileutils_label = '' + @fileutils_verbose = true + @fileutils_nowrite = true + + FileUtils::OPT_TABLE.each do |name, opts| + next unless opts.include?('noop') + module_eval(<<-EOS, __FILE__, __LINE__ + 1) + def #{name}(*args) + @fileutils_verbose = true unless defined?(@fileutils_verbose) + @fileutils_nowrite = true unless defined?(@fileutils_nowrite) + super(*fu_update_option(args, :noop => true, :verbose => true)) + end + EOS + end + extend self + end + +end |