class GNOME2::Rake::SourceDownloadTask - glib2-3.1.1 Documentation

# class GNOME2::Rake::SourceDownloadTask

### Public Class Methods

new(package) click to toggle source

    # File lib/gnome2/rake/source-download-task.rb, line 28
    def initialize(package)
      @package = package
    end

### Public Instance Methods

define() click to toggle source

    # File lib/gnome2/rake/source-download-task.rb, line 32
    def define
      namespace :source do
        namespace :downloader do
          task :before
          define_download_tasks
          download_tasks = @package.external_packages.collect do |package|
            "source:downloader:download:#{package.name}"
          end
          task :download => download_tasks
          task :after
        end

        desc "Dowanload sources"
        task :download => [
          "source:downloader:before",
          "source:downloader:download",
          "source:downloader:after",
        ]
      end
    end

### Private Instance Methods

define_download_tasks() click to toggle source

    # File lib/gnome2/rake/source-download-task.rb, line 54
    def define_download_tasks
      namespace :download do
        @package.external_packages.each do |package|
          download_dir = @package.download_dir
          tar_full_path = download_dir + package.archive_base_name

          task :before
          task :after
          desc "Download #{package.label} into #{download_dir}."
          # task package[:name] => [:before, tar_full_path.to_s, :after]
          task package[:name] => tar_full_path.to_s

          directory_path = tar_full_path.dirname
          directory directory_path.to_s
          file tar_full_path.to_s => directory_path.to_s do
            archive_url = package.archive_url
            rake_output_message "Downloading... #{archive_url}"
            download(archive_url, tar_full_path)
          end
        end
      end
    end

download(url, output_path) click to toggle source

    # File lib/gnome2/rake/source-download-task.rb, line 77
    def download(url, output_path)
      OpenURI.singleton_class.class_eval do
        alias_method :redirectable_original?, :redirectable?
        def redirectable?(uri1, uri2)
          redirectable_original?(uri1, uri2) or
            (uri1.scheme.downcase == "http" and
             uri2.scheme.downcase == "https")
        end
      end
      begin
        open(url) do |input|
          output_path.open("wb") do |output_file|
            output_file.print(input.read)
          end
        end
      ensure
        OpenURI.singleton_class.class_eval do
          alias_method :redirectable?, :redirectable_original?
          remove_method :redirectable_original?
        end
      end
    end

redirectable?(uri1, uri2) click to toggle source

    # File lib/gnome2/rake/source-download-task.rb, line 80
    def redirectable?(uri1, uri2)
      redirectable_original?(uri1, uri2) or
        (uri1.scheme.downcase == "http" and
         uri2.scheme.downcase == "https")
    end