From d465f8ca9937e871caa409988f5909b2b0f0f843 Mon Sep 17 00:00:00 2001 From: Nikhil Benesch Date: Sun, 4 May 2014 02:56:07 -0400 Subject: CHEF-4423: extract CookbookVersion manifest update into public method Certain segments of a CookbookVersion's manifest (recipe, attributes) have custom setter methods. Extract the logic to handle these special cases into a public method to reduce duplication. --- lib/chef/cookbook_version.rb | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) (limited to 'lib/chef/cookbook_version.rb') diff --git a/lib/chef/cookbook_version.rb b/lib/chef/cookbook_version.rb index 27dc8ef9e5..cbae3a552d 100644 --- a/lib/chef/cookbook_version.rb +++ b/lib/chef/cookbook_version.rb @@ -169,14 +169,7 @@ class Chef next unless @manifest.has_key?(segment) filenames = @manifest[segment].map{|manifest_record| manifest_record['name']} - if segment == :recipes - self.recipe_filenames = filenames - elsif segment == :attributes - self.attribute_filenames = filenames - else - segment_filenames(segment).clear - filenames.each { |filename| segment_filenames(segment) << filename } - end + replace_segment_filenames(segment, filenames) end end @@ -272,6 +265,17 @@ class Chef end end + def replace_segment_filenames(segment, filenames) + case segment.to_sym + when :recipes + self.recipe_filenames = filenames + when :attributes + self.attribute_filenames = filenames + else + segment_filenames(segment).replace(filenames) + end + end + # Query whether a template file +template_filename+ is available. File # specificity for the given +node+ is obeyed in the lookup. def has_template_for_node?(node, template_filename) -- cgit v1.2.1