summaryrefslogtreecommitdiff
path: root/lib/chef/monkey_patches/pathname.rb
blob: c0255ae7eab2d6d852e5f8b4225996022e7fd4bd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
require 'pathname'

if RUBY_VERSION.to_f < 1.9
  class Pathname
    @@old_each_filename = instance_method(:each_filename)

    def each_filename(&block)
      if block_given?
        EachFilenameEnumerable.new(self).each(&block)
      else
        EachFilenameEnumerable.new(self)
      end
    end

    def old_each_filename(&block)
      @@old_each_filename.bind(self).call(&block)
    end

    class EachFilenameEnumerable
      include Enumerable
      attr_reader :pathname

      def initialize(pathname)
        @pathname = pathname
      end

      def each(&block)
        @pathname.old_each_filename(&block)
      end
    end
  end
end