Class/Module Index [+]

Quicksearch

PhusionPassenger::Utils::Download

Public Class Methods

included(klass) click to toggle source
# File lib/phusion_passenger/utils/download.rb, line 34
def self.included(klass)
        # When included into another class, make sure that Utils
        # methods are made private.
        public_instance_methods(false).each do |method_name|
                klass.send(:private, method_name)
        end
end

Public Instance Methods

download(url, output, options = {}) click to toggle source

Downloads a file from the given URL and saves it to the given filename. Returns whether the download succeeded.

Options:

show_progress: whether to show download progress. Default: false.
logger: the logger to use. If not given, this function will log to STDERR.
cacert: a CA certificate file to use for verifying SSL websites.
        The default is to use the download tool's down CA database.
use_cache: Whether to copy the file from the download cache, if available.
           Default: false.
# File lib/phusion_passenger/utils/download.rb, line 53
def download(url, output, options = {})
        logger = options[:logger] || Logger.new(STDERR)

        if options[:use_cache] && cache_dir = PhusionPassenger.download_cache_dir
                basename = basename_from_url(url)
                if File.exist?("#{cache_dir}/#{basename}")
                        logger.info "Copying #{basename} from #{cache_dir}..."
                        FileUtils.cp("#{cache_dir}/#{basename}", output)
                        return true
                end
        end

        if PlatformInfo.find_command("curl")
                return download_with_curl(logger, url, output, options)
        elsif PlatformInfo.find_command("wget")
                return download_with_wget(logger, url, output, options)
        else
                logger.error "Could not download #{url}: no download tool found (curl or wget required)"
                return false
        end
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.