chef/lib/chef/cookbook_version.rb
# Determine the manifest records from the most specific directory
# for the given node. See #preferred_manifest_record for a
# description of entries of the returned Array.
Determine the manifest records from the most specific directory
for the given node. See #preferred_manifest_record for a
description of entries of the returned Array.
Determine the manifest records from the most specific directory for the given node . See #preferred_manifest_record for a description of entries of the returned Array .
def preferred_manifest_records_for_directory(node, segment, dirname)
      preferences = preferences_for_path(node, segment, dirname)
      records_by_pref = Hash.new
      preferences.each { |pref| records_by_pref[pref] = Array.new }
      manifest[segment].each do |manifest_record|
        manifest_record_path = manifest_record[:path]
        if manifest_record_path =~ /(#{Regexp.escape(segment.to_s)}\/[^\/]+\/#{Regexp.escape(dirname)})\/.+$/
          specificity_dirname = $1
          if records_by_pref[specificity_dirname]
            records_by_pref[specificity_dirname] << manifest_record
          end
        end
      end
      best_pref = preferences.find { |pref| !records_by_pref[pref].empty? }
      raise Chef::Exceptions::FileNotFound, "cookbook #{name} (#{version}) has no directory #{segment}/default/#{dirname}" unless best_pref
      records_by_pref[best_pref]
    end
def preferred_manifest_records_for_directory ( node , segment , dirname ) preferences = preferences_for_path ( node , segment , dirname ) records_by_pref = Hash . new preferences . each { | pref | records_by_pref [ pref ] = Array . new } manifest [ segment ] . each do | manifest_record | manifest_record_path = manifest_record [ :path ] if manifest_record_path =~ / ( #{ Regexp . escape ( segment . to_s ) } \/ [^ \/ ]+ \/ #{ Regexp . escape ( dirname ) } ) \/ .+$ / specificity_dirname = $1 if records_by_pref [ specificity_dirname ] records_by_pref [ specificity_dirname ] << manifest_record end end end best_pref = preferences . find { | pref | ! records_by_pref [ pref ] . empty? } raise Chef :: Exceptions :: FileNotFound , "cookbook #{name} (#{version}) has no directory #{segment}/default/#{dirname}" unless best_pref records_by_pref [ best_pref ] end
Determine the manifest records from the most specific directory
for the given node.
Determine the manifest records from the most specific directory for the given node .
# extract the preference part from the path. # Note the specificy_dirname includes the segment and # dirname argument as above, which is what # preferences_for_path returns. It could be # "files/ubuntu-9.10/dirname", for example. # Record the specificity_dirname only if it's in the list of # valid preferences
node
<not_specific>
segment
<not_specific>
dirname
<not_specific>