class Berkshelf::Installer::Worker

def initialize(berksfile)

def initialize(berksfile)
  @berksfile  = berksfile
  @downloader = Downloader.new(berksfile)
end

def install(dependency)

Returns:
  • (CachedCookbook) -

Parameters:
  • (Dependency) --
def install(dependency)
  Berkshelf.log.info "Installing #{dependency}"
  if dependency.installed?
    Berkshelf.log.debug "  Already installed - skipping install"
    Berkshelf.formatter.use(dependency)
    dependency.cached_cookbook
  else
    name, version = dependency.name, dependency.locked_version.to_s
    source = berksfile.source_for(name, version)
    # Raise error if our Berksfile.lock has cookbook versions that
    # can't be found in sources
    raise MissingLockfileCookbookVersion.new(name, version, "in any of the sources") unless source
    Berkshelf.log.debug "  Downloading #{dependency.name} (#{dependency.locked_version}) from #{source}"
    cookbook = source.cookbook(name, version)
    Berkshelf.log.debug "    => #{cookbook.inspect}"
    Berkshelf.formatter.install(source, cookbook)
    downloader.download(name, version) do |stash|
      CookbookStore.import(name, version, stash)
    end
  end
end