summaryrefslogtreecommitdiff
path: root/lib/chef/monkey_patches
diff options
context:
space:
mode:
authorJohn Keiser <jkeiser@opscode.com>2014-04-23 11:09:19 -0700
committerJohn Keiser <jkeiser@opscode.com>2014-04-23 11:09:19 -0700
commit81818db3e9859602b3bd2668050531db111635e0 (patch)
treeb3697c891c16a462495410fe3dea89e94b60e2ed /lib/chef/monkey_patches
parent9c38c558f0c280edec9e91a97aa9ecafc41938e4 (diff)
downloadchef-81818db3e9859602b3bd2668050531db111635e0.tar.gz
Fix Pathname.each_filename on Ruby 1.8.7
Diffstat (limited to 'lib/chef/monkey_patches')
-rw-r--r--lib/chef/monkey_patches/pathname.rb32
1 files changed, 32 insertions, 0 deletions
diff --git a/lib/chef/monkey_patches/pathname.rb b/lib/chef/monkey_patches/pathname.rb
new file mode 100644
index 0000000000..c0255ae7ea
--- /dev/null
+++ b/lib/chef/monkey_patches/pathname.rb
@@ -0,0 +1,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