# File lib/chef/cookbook_loader.rb, line 41 def initialize(*repo_paths) repo_paths = repo_paths.flatten raise ArgumentError, "You must specify at least one cookbook repo path" if repo_paths.empty? @cookbooks_by_name = Mash.new @loaded_cookbooks = {} @metadata = Mash.new @cookbooks_paths = Hash.new {|h,k| h[k] = []} # for deprecation warnings @chefignores = {} @repo_paths = repo_paths.map do |repo_path| repo_path = File.expand_path(repo_path) end # Used to track which cookbooks appear in multiple places in the cookbook repos # and are merged in to a single cookbook by file shadowing. This behavior is # deprecated, so users of this class may issue warnings to the user by checking # this variable @merged_cookbooks = [] end
# File lib/chef/cookbook_loader.rb, line 102 def [](cookbook) if @cookbooks_by_name.has_key?(cookbook.to_sym) or load_cookbook(cookbook.to_sym) @cookbooks_by_name[cookbook.to_sym] else raise Exceptions::CookbookNotFoundInRepo, "Cannot find a cookbook named #{cookbook.to_s}; did you forget to add metadata to a cookbook? (http://wiki.opscode.com/display/chef/Metadata)" end end
# File lib/chef/cookbook_loader.rb, line 124 def cookbook_names @cookbooks_by_name.keys.sort end
# File lib/chef/cookbook_loader.rb, line 118 def each @cookbooks_by_name.keys.sort { |a,b| a.to_s <=> b.to_s }.each do |cname| yield(cname, @cookbooks_by_name[cname]) end end
# File lib/chef/cookbook_loader.rb, line 112 def has_key?(cookbook_name) not self[cookbook_name.to_sym].nil? end
# File lib/chef/cookbook_loader.rb, line 75 def load_cookbook(cookbook_name, repo_paths=nil) repo_paths ||= @repo_paths repo_paths.each do |repo_path| @chefignores[repo_path] ||= Cookbook::Chefignore.new(repo_path) cookbook_path = File.join(repo_path, cookbook_name.to_s) next unless File.directory?(cookbook_path) and Dir[File.join(repo_path, "*")].include?(cookbook_path) loader = Cookbook::CookbookVersionLoader.new(cookbook_path, @chefignores[repo_path]) loader.load_cookbooks next if loader.empty? cookbook_name = loader.cookbook_name @cookbooks_paths[cookbook_name] << cookbook_path # for deprecation warnings if @loaded_cookbooks.key?(cookbook_name) @merged_cookbooks << cookbook_name # for deprecation warnings @loaded_cookbooks[cookbook_name].merge!(loader) else @loaded_cookbooks[cookbook_name] = loader end end if @loaded_cookbooks.has_key?(cookbook_name) cookbook_version = @loaded_cookbooks[cookbook_name].cookbook_version @cookbooks_by_name[cookbook_name] = cookbook_version @metadata[cookbook_name] = cookbook_version.metadata end @cookbooks_by_name[cookbook_name] end
# File lib/chef/cookbook_loader.rb, line 66 def load_cookbooks @repo_paths.each do |repo_path| Dir[File.join(repo_path, "*")].each do |cookbook_path| load_cookbook(File.basename(cookbook_path), [repo_path]) end end @cookbooks_by_name end
# File lib/chef/cookbook_loader.rb, line 60 def merged_cookbook_paths # for deprecation warnings merged_cookbook_paths = {} @merged_cookbooks.each {|c| merged_cookbook_paths[c] = @cookbooks_paths[c]} merged_cookbook_paths end
# File lib/chef/cookbook_loader.rb, line 128 def values @cookbooks_by_name.values end
Generated with the Darkfish Rdoc Generator 2.