fileutils.patch

Thomas Sawyer, 03/01/2013 05:29 PM

Download (1.81 KB)

View differences:

lib/fileutils.rb
88 88
  extend self
89 89

  
90 90
  #
91
  # To overcome Ruby's "Module Inclusion Problem", whenever a module
92
  # is included into FileUtils, then the sub-modules re-include
93
  # FileUtils to ensure inclusion of the new module as well.
94
  #
95
  def self.include(mod)
96
    super mod
97
    extend self
98
    [Verbose, NoWrite, DryRun].each do |base|
99
      base.send(:include, self) #FileUtils)
100
      base.extend(base)  # extend self
101
    end
102
  end
103

  
104
  #
91 105
  # This module has all methods of FileUtils module, but it outputs messages
92 106
  # before acting.  This equates to passing the <tt>:verbose</tt> flag to
93 107
  # methods in FileUtils.
......
1255 1269
  end
1256 1270

  
1257 1271
  include StreamUtils_
1258
  extend StreamUtils_
1259 1272

  
1260 1273
  class Entry_   #:nodoc: internal use only
1261 1274
    include StreamUtils_
test/fileutils/test_inclusion.rb
1
require 'fileutils'
2
require 'test/unit'
3

  
4
class TestFileUtilsInclusion < Test::Unit::TestCase
5

  
6
  module Foo
7
    def foo?; true; end
8
  end
9

  
10
  def test_include_into_all_submodules
11
    ::FileUtils.send(:include, Foo)
12

  
13
    assert ::FileUtils.ancestors.include?(Foo)
14
    assert ::FileUtils::NoWrite.ancestors.include?(Foo)
15
    assert ::FileUtils::Verbose.ancestors.include?(Foo)
16
    assert ::FileUtils::DryRun.ancestors.include?(Foo)
17

  
18
    assert ::FileUtils::NoWrite.foo?
19
    assert ::FileUtils::Verbose.foo?
20
    assert ::FileUtils::DryRun.foo?
21
    assert ::FileUtils.foo?
22
  end
23

  
24
  def test_includes_streamutils
25
    assert_include(::FileUtils::Verbose.private_instance_methods(true), :fu_stream_blksize)
26
  end
27

  
28
end