diff --git a/ChangeLog b/ChangeLog index 3efda1f7bc..b0084231fc 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +Tue Feb 17 01:20:57 2004 Minero Aoki + + * lib/fileutils.rb: new module FileUtils::DryRun. + Mon Feb 16 23:28:14 2004 NAKAMURA, Hiroshi * 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 :noop 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 + + # + # 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 -