def load_cookbook(path_or_name)
      require "chef/exceptions"
      if File.directory?(path_or_name)
        cookbook_path = path_or_name
        # First, is there a cookbook in the specified dir that matches?
        require "chef/cookbook/cookbook_version_loader"
        begin
          v = Chef::Cookbook::CookbookVersionLoader.new(cookbook_path)
          v.load!
          cookbook = v.cookbook_version
        rescue Chef::Exceptions::CookbookNotFoundInRepo
          raise InvalidCookbook.new(cookbook_path)
        end
      else
        cookbook_name = path_or_name
        # Second, is there a cookbook in their local repository that matches?
        require "chef/cookbook_loader"
        cb_loader = Chef::CookbookLoader.new(cookbook_repo_paths)
        cb_loader.load_cookbooks_without_shadow_warning

        begin
          cookbook = cb_loader[cookbook_name]
        rescue Chef::Exceptions::CookbookNotFoundInRepo
          cookbook_repo_paths.each do |repo_path|
            cookbook_path = File.join(repo_path, cookbook_name)
            if File.directory?(cookbook_path)
              raise InvalidCookbook.new(cookbook_path)
            end
          end
          raise CookbookNotFound.new(cookbook_name, cookbook_repo_paths)
        end
      end
      cookbook
    end
def load_cookbook(path_or_name)
      require "chef/exceptions"
      if File.directory?(path_or_name)
        cookbook_path = path_or_name
        # First, is there a cookbook in the specified dir that matches?
        require "chef/cookbook/cookbook_version_loader"
        begin
          v = Chef::Cookbook::CookbookVersionLoader.new(cookbook_path)
          v.load!
          cookbook = v.cookbook_version
        rescue Chef::Exceptions::CookbookNotFoundInRepo
          raise InvalidCookbook.new(cookbook_path)
        end
      else
        cookbook_name = path_or_name
        # Second, is there a cookbook in their local repository that matches?
        require "chef/cookbook_loader"
        cb_loader = Chef::CookbookLoader.new(cookbook_repo_paths)
        cb_loader.load_cookbooks_without_shadow_warning

        begin
          cookbook = cb_loader[cookbook_name]
        rescue Chef::Exceptions::CookbookNotFoundInRepo
          cookbook_repo_paths.each do |repo_path|
            cookbook_path = File.join(repo_path, cookbook_name)
            if File.directory?(cookbook_path)
              raise InvalidCookbook.new(cookbook_path)
            end
          end
          raise CookbookNotFound.new(cookbook_name, cookbook_repo_paths)
        end
      end
      cookbook
    end
Given a cookbook path or name, try to load that cookbook. Either return
 a cookbook object or raise an error.