class Berkshelf::Shelf

All tasks that operate on the Berkshelf shelf.

def contingencies(cookbook)

Returns:
  • (Array) -

Parameters:
  • cookbook (Berkshelf::CachedCookbook) --
def contingencies(cookbook)
  store.cookbooks.select { |c| c.dependencies.include?(cookbook.cookbook_name) }
end

def find(name, version = nil)

Returns:
  • (Array) -

Raises:
  • (CookbookNotFound) -

Parameters:
  • version (String, nil) --
  • name (String) --
def find(name, version = nil)
  cookbooks =
    if version
      [store.cookbook(name, version)].compact
    else
      store.cookbooks(name).sort
    end
  if cookbooks.empty?
    raise CookbookNotFound.new(name, version, "in the Berkshelf shelf")
  end
  cookbooks
end

def list

def list
  cookbooks = store.cookbooks.inject({}) do |hash, cookbook|
    (hash[cookbook.cookbook_name] ||= []).push(cookbook.version)
    hash
  end
  if cookbooks.empty?
    Berkshelf.formatter.msg "There are no cookbooks in the Berkshelf shelf"
  else
    Berkshelf.formatter.msg "Cookbooks in the Berkshelf shelf:"
    cookbooks.sort.each do |cookbook, versions|
      Berkshelf.formatter.msg("  * #{cookbook} (#{versions.sort.join(", ")})")
    end
  end
end

def show(name)

def show(name)
  cookbooks = find(name, options[:version])
  if options[:version]
    Berkshelf.formatter.msg "Displaying '#{name}' (#{options[:version]}) in the Berkshelf shelf:"
  else
    Berkshelf.formatter.msg "Displaying all versions of '#{name}' in the Berkshelf shelf:"
  end
  cookbooks.each do |cookbook|
    Berkshelf.formatter.info(cookbook)
    Berkshelf.formatter.msg("\n")
  end
end

def store

Returns:
  • (Berkshelf::CookbookStore) -
def store
  Berkshelf.cookbook_store
end

def uninstall(name)

def uninstall(name)
  cookbooks = find(name, options[:version])
  cookbooks.each { |c| uninstall_cookbook(c, options[:force]) }
end

def uninstall_cookbook(cookbook, force = false)

Parameters:
  • force (Boolean) --
  • cookbook (Berkshelf::CachedCookbook) --
def uninstall_cookbook(cookbook, force = false)
  unless options[:force] || (contingent = contingencies(cookbook)).empty?
    contingent = contingent.map { |c| "#{c.cookbook_name} (#{c.version})" }.join(", ")
    confirm = Berkshelf.ui.ask("[#{contingent}] depend on #{cookbook.cookbook_name}.\n\nAre you sure you want to continue? (y/N)")
    exit unless confirm.to_s.upcase[0] == "Y"
  end
  FileUtils.rm_rf(cookbook.path)
  Berkshelf.formatter.msg("Successfully uninstalled #{cookbook.cookbook_name} (#{cookbook.version})")
end