class ChefCLI::Policyfile::ChefRepoCookbookSource

def ==(other)

def ==(other)
  other.is_a?(self.class) && other.path == path && other.preferred_cookbooks == preferred_cookbooks
end

def cookbook_repo

Returns:
  • (Chef::CookbookLoader) - cookbook loader using on disk FileVendor
def cookbook_repo
  @cookbook_repo ||= begin
    Chef::Cookbook::FileVendor.fetch_from_disk(path)
    Chef::CookbookLoader.new(path)
  end
end

def cookbook_version_paths

Returns:
  • (Hash) - cookbook_version_paths
def cookbook_version_paths
  slurp_metadata! if @cookbook_version_paths.nil?
  @cookbook_version_paths
end

def default_source_args

def default_source_args
  [:chef_repo, path]
end

def desc

def desc
  "chef_repo(#{path})"
end

def initialize(path)

Parameters:
  • path (String) -- path to a chef-repo or the cookbook path under it
def initialize(path)
  self.path = path
  @ui = UI.new
  @preferred_cookbooks = []
  yield self if block_given?
end

def null?

def null?
  false
end

def path=(path)

Parameters:
  • path (String) -- path to a chef-repo or the cookbook path under it
def path=(path)
  cookbooks_path = "#{path}/cookbooks"
  if Dir.exist?(cookbooks_path)
    @path = cookbooks_path
  else
    @path = path
  end
end

def preferred_for(*cookbook_names)

def preferred_for(*cookbook_names)
  preferred_cookbooks.concat(cookbook_names)
end

def preferred_source_for?(cookbook_name)

def preferred_source_for?(cookbook_name)
  preferred_cookbooks.include?(cookbook_name)
end

def slurp_metadata!

from the Chef::CookbookLoader on-disk cookbook repo.
Helper to compute the @universe_graph and @cookbook_version_paths once
def slurp_metadata!
  @universe_graph = {}
  @cookbook_version_paths = {}
  cookbook_repo.load_cookbooks
  cookbook_repo.each do |cookbook_name, cookbook_version|
    metadata = cookbook_version.metadata
    if metadata.name.nil?
      ui.err("WARN: #{cookbook_name} cookbook missing metadata or no name field, skipping")
      next
    end
    @universe_graph[metadata.name] ||= {}
    @universe_graph[metadata.name][metadata.version] = metadata.dependencies.to_a
    @cookbook_version_paths[metadata.name] ||= {}
    @cookbook_version_paths[metadata.name][metadata.version] = cookbook_version.root_dir
  end
end

def source_options_for(cookbook_name, cookbook_version)

Returns:
  • (Hash) - metadata for a single cookbook version
def source_options_for(cookbook_name, cookbook_version)
  { path: cookbook_version_paths[cookbook_name][cookbook_version], version: cookbook_version }
end

def universe_graph

Returns:
  • (Hash) - universe_graph
def universe_graph
  slurp_metadata! if @universe_graph.nil?
  @universe_graph
end