Sha256: b4eccf7829646962edb3cf4ad3ac0d6c130f4cd5b18362164ceb4a6e9bc6b5a1

Contents?: true

Size: 1.4 KB

Versions: 27

Compression:

Stored size: 1.4 KB

Contents

# == DownloadManager
#
# The DownloadManager provides a way of downloading files.
module AutomateIt
  class DownloadManager < Plugin::Manager
    alias_methods :download

    # Downloads the +source+ document.
    #
    # Options:
    # * :to -- Saves source to this filename or directory. Defaults to current directory.
    def download(*arguments) dispatch(*arguments) end

    # == DownloadManager::BaseDriver
    #
    # Base class for all DownloadManager drivers.
    class BaseDriver < Plugin::Driver
    end

    # == DownloadManager::OpenURI
    #
    # A DownloadManager driver using the OpenURI module for handling HTTP and FTP transfers.
    class OpenURI < BaseDriver
      depends_on :libraries => %w(open-uri)

      def suitability(method, *args) # :nodoc:
        return available? ? 1 : 0
      end

      # See DownloadManager#download
      def download(*arguments)
        args, opts = args_and_opts(*arguments)
        source = args[0] or raise ArgumentError.new("No source specified")
        target = args[1] || opts[:to] || File.basename(source)
        target = File.join(target, File.basename(source)) if File.directory?(target)
        log.info(PNOTE+"Downloading #{target}")
        if writing?
          open(target, "w+") do |writer|
            open(source) do |reader|
              writer.write(reader.read)
            end
          end
        end
        return writing?
      end
    end
  end
end

Version data entries

27 entries across 27 versions & 2 rubygems

Version Path
automate-it-0.9.2 lib/automateit/download_manager.rb
automate-it-0.9.1 lib/automateit/download_manager.rb
automate-it-0.9.0 lib/automateit/download_manager.rb
automateit-0.71021 lib/automateit/download_manager.rb
automateit-0.71030 lib/automateit/download_manager.rb
automateit-0.71031.1 lib/automateit/download_manager.rb
automateit-0.71031.2 lib/automateit/download_manager.rb
automateit-0.71006 lib/automateit/download_manager.rb
automateit-0.71012 lib/automateit/download_manager.rb
automateit-0.71017 lib/automateit/download_manager.rb
automateit-0.71102 lib/automateit/download_manager.rb
automateit-0.71103 lib/automateit/download_manager.rb
automateit-0.71101 lib/automateit/download_manager.rb
automateit-0.71101.2 lib/automateit/download_manager.rb
automateit-0.71101.1 lib/automateit/download_manager.rb
automateit-0.71031 lib/automateit/download_manager.rb
automateit-0.71220 lib/automateit/download_manager.rb
automateit-0.71221 lib/automateit/download_manager.rb
automateit-0.71104 lib/automateit/download_manager.rb
automateit-0.71111 lib/automateit/download_manager.rb