Sha256: 705d2920dfa2258a9973e019304f8a05786bee93a05c31f758cdaed5902f0c4c

Contents?: true

Size: 1.93 KB

Versions: 29

Compression:

Stored size: 1.93 KB

Contents

require 'open-uri'
require_relative '../tasklib'
require_relative '../template'

module RakeDependencies
  module Tasks
    class Download < TaskLib
      parameter :name, default: :download

      parameter :type, default: :zip
      parameter :os_ids, default: {mac: 'mac', linux: 'linux'}

      parameter :distribution_directory, default: 'dist'

      parameter :dependency, required: true
      parameter :version
      parameter :path, required: true
      parameter :uri_template, required: true
      parameter :file_name_template, required: true

      def process_arguments(args)
        super(args)
        self.name = args[0] if args[0]
      end

      def define
        desc "Download #{dependency} distribution"
        task name do
          parameters = {
              version: version,
              platform: platform,
              os_id: os_id,
              ext: ext
          }

          uri = Template.new(uri_template)
            .with_parameters(parameters)
            .render
          download_file_name = Template.new(file_name_template)
            .with_parameters(parameters)
            .render
          download_file_directory = File.join(path, distribution_directory)
          download_file_path = File.join(download_file_directory, download_file_name)

          temporary_file = open(uri)

          mkdir_p download_file_directory
          cp temporary_file.path, download_file_path
        end
      end

      private

      def os_id
        os_ids[platform]
      end

      def platform
        RUBY_PLATFORM =~ /darwin/ ? :mac : :linux
      end

      def resolved_type
        type.is_a?(Hash) ? type[platform].to_sym : type.to_sym
      end

      def ext
        case resolved_type
          when :tar_gz then '.tar.gz'
          when :tgz then '.tgz'
          when :zip then '.zip'
          when :uncompressed then ''
          else
            raise "Unknown type: #{type}"
        end
      end
    end
  end
end

Version data entries

29 entries across 29 versions & 2 rubygems

Version Path
rake_dependencies-0.23.0 lib/rake_dependencies/tasks/download.rb
rake_dependencies-0.22.0.pre.pre.2 lib/rake_dependencies/tasks/download.rb
rake_dependencies-0.22.0.pre.pre.1 lib/rake_dependencies/tasks/download.rb
rake_dependencies-0.21.0 lib/rake_dependencies/tasks/download.rb
rake_dependencies-0.20.0.pre.pre.2 lib/rake_dependencies/tasks/download.rb
rake_dependencies-0.20.0.pre.pre.1 lib/rake_dependencies/tasks/download.rb
rake_dependencies-0.19.0 lib/rake_dependencies/tasks/download.rb
rake_dependencies-0.18.1.pre1 lib/rake_dependencies/tasks/download.rb
rake_dependencies-0.18.0 lib/rake_dependencies/tasks/download.rb
rake_dependencies-0.17.1.pre2 lib/rake_dependencies/tasks/download.rb
rake_dependencies-0.17.1.pre1 lib/rake_dependencies/tasks/download.rb
rake_dependencies-0.17.0 lib/rake_dependencies/tasks/download.rb
rake_dependencies-0.16.1.pre3 lib/rake_dependencies/tasks/download.rb
rake_dependencies-0.16.1.pre2 lib/rake_dependencies/tasks/download.rb
rake_dependencies-0.16.1.pre1 lib/rake_dependencies/tasks/download.rb
rake_dependencies-0.16.0 lib/rake_dependencies/tasks/download.rb
rake_dependencies-0.15.2.pre1 lib/rake_dependencies/tasks/download.rb
rake_dependencies-0.15.1 lib/rake_dependencies/tasks/download.rb
rake_dependencies-0.15.0 lib/rake_dependencies/tasks/download.rb
rake_dependencies-0.14.1 lib/rake_dependencies/tasks/download.rb