Module: FileUtils

Defined in:
lib/fileutils_logger.rb

Defined Under Namespace

Classes: LoggerAdapter

Class Method Summary collapse

Class Method Details

.cd(dir, options = {}, &block) ⇒ Object

Monkey patch original source code is here:

https://github.com/ruby/ruby/blob/v2_0_0_247/lib/fileutils.rb#L122


11
12
13
14
15
16
17
# File 'lib/fileutils_logger.rb', line 11

def cd(dir, options = {}, &block) # :yield: dir
  fu_check_options options, OPT_TABLE['cd']
  fu_output_message "cd #{dir}" if options[:verbose]
  r = Dir.chdir(dir, &block)
  fu_output_message 'cd -' if options[:verbose] and block
  return r # this is difference from original and this is important!
end

.chdirObject

Monkey patch original source code is here:

https://github.com/ruby/ruby/blob/v2_0_0_247/lib/fileutils.rb#L122


20
21
22
23
24
25
26
# File 'lib/fileutils_logger.rb', line 20

def cd(dir, options = {}, &block) # :yield: dir
  fu_check_options options, OPT_TABLE['cd']
  fu_output_message "cd #{dir}" if options[:verbose]
  r = Dir.chdir(dir, &block)
  fu_output_message 'cd -' if options[:verbose] and block
  return r # this is difference from original and this is important!
end

.with_logger(logger, level = :info) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/fileutils_logger.rb', line 24

def with_logger(logger, level = :info)
  output = LoggerAdapter.new(logger, level)

  Module.new do
    include FileUtils
    @fileutils_output  = output
    @fileutils_label   = ''

    ::FileUtils.collect_method(:verbose).each do |name|
      module_eval("        def \#{name}(*args)\n          super(*fu_update_option(args, :verbose => true))\n        end\n        private :\#{name}\n      EOS\n    end\n\n    extend self\n    class << self\n      ::FileUtils::METHODS.each do |m|\n        public m\n      end\n    end\n  end\n\nend\n", __FILE__, __LINE__ + 1)