diff options
Diffstat (limited to 'lib/chef')
-rw-r--r-- | lib/chef/cookbook/cookbook_version_loader.rb | 2 | ||||
-rw-r--r-- | lib/chef/cookbook_version.rb | 19 | ||||
-rw-r--r-- | lib/chef/monkey_patches/pathname.rb | 32 |
3 files changed, 39 insertions, 14 deletions
diff --git a/lib/chef/cookbook/cookbook_version_loader.rb b/lib/chef/cookbook/cookbook_version_loader.rb index be03db2d7a..7d876c685e 100644 --- a/lib/chef/cookbook/cookbook_version_loader.rb +++ b/lib/chef/cookbook/cookbook_version_loader.rb @@ -17,7 +17,7 @@ class Chef :resource_filenames, :provider_filenames] - UPLOADED_COOKBOOK_VERSION_FILE = ".uploaded-cookbook-version.json" + UPLOADED_COOKBOOK_VERSION_FILE = ".uploaded-cookbook-version.json".freeze attr_reader :cookbook_name attr_reader :cookbook_settings diff --git a/lib/chef/cookbook_version.rb b/lib/chef/cookbook_version.rb index 21d435141c..6f2f939f6b 100644 --- a/lib/chef/cookbook_version.rb +++ b/lib/chef/cookbook_version.rb @@ -26,6 +26,8 @@ require 'chef/recipe' require 'chef/cookbook/file_vendor' require 'chef/cookbook/metadata' require 'chef/version_class' +require 'pathname' +require 'chef/monkey_patches/pathname' class Chef @@ -617,23 +619,14 @@ class Chef # This happens to also support cookbook name != directory name. if root_dir pathname = Pathname.new(segment_file).relative_path_from(Pathname.new(root_dir)) - - # This insane dance brought to you by Ruby 1.8.7. - # Rather do specificity = pathname.each_filename.to_a? Me too. - i = 0 - parts = [] - pathname.each_filename do |part| - parts << part - break if i == 1 - i += 1 - end + part_1, part_2 = pathname.each_filename.first(2) # If the path is actually under root_dir ... - if parts[0] != '..' + if part_1 != '..' # Grab the file name and specificity - file_name = pathname.basename + file_name = part_1 if segment == :templates || segment == :files - specificity = parts[1] + specificity = part_2 else specificity = 'default' end 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 |