class Berkshelf::Installer::Worker

Attributes

berksfile[R]
downloader[R]

Public Class Methods

new(berksfile) click to toggle source
# File lib/berkshelf/installer.rb, line 73
def initialize(berksfile)
  @berksfile  = berksfile
  @downloader = Downloader.new(berksfile)
end

Public Instance Methods

install(dependency) click to toggle source

Install a specific dependency.

@param [Dependency]

the dependency to install

@return [CachedCookbook]

the installed cookbook
# File lib/berkshelf/installer.rb, line 84
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