Method: Berkshelf::Downloader#download

Defined in:
lib/berkshelf/downloader.rb

#download(*args, &block) ⇒ String

Download the given Berkshelf::Dependency. If the optional block is given, the temporary path to the cookbook is yielded and automatically deleted when the block returns. If no block is given, it is the responsibility of the caller to remove the tmpdir.

Parameters:

  • name (String)
  • version (String)
  • options (Hash)

    a customizable set of options

Returns:

Raises:



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/berkshelf/downloader.rb', line 36

def download(*args, &block)
  # options are ignored
  # options = args.last.is_a?(Hash) ? args.pop : Hash.new
  dependency, version = args

  sources.each do |source|
    if ( result = try_download(source, dependency, version) )
      if block_given?
        value = yield result
        FileUtils.rm_rf(result)
        return value
      end

      return result
    end
  end

  raise CookbookNotFound.new(dependency, version, "in any of the sources")
end