Sha256: 45b59fc6dbf5fb5328375bb8f8ccd0ed9ba73ed7931fabb22141eca2995cd74d

Contents?: true

Size: 1.98 KB

Versions: 11

Compression:

Stored size: 1.98 KB

Contents

# frozen_string_literal: true

require 'rake_factory'
require 'rubygems'

require_relative '../template'

module RakeDependencies
  module Tasks
    class Install < RakeFactory::Task
      default_name :install
      default_description(RakeFactory::DynamicValue.new do |t|
        "Install #{t.dependency}"
      end)

      parameter :platform_cpu_names, default: PlatformNames::CPU
      parameter :platform_os_names, default: PlatformNames::OS

      parameter :dependency, required: true
      parameter :version
      parameter :path, required: true
      parameter :type, default: :zip

      parameter :binary_directory, default: 'bin'
      parameter :binary_name_template, required: true

      parameter :installation_directory, required: true

      action do
        parameters = {
          version: version,
          platform: platform,
          platform_cpu_name: platform_cpu_name,
          platform_os_name: platform_os_name,
          ext: ext
        }

        binary_file_name = Template.new(binary_name_template)
                                   .with_parameters(parameters)
                                   .render
        binary_file_directory = File.join(path, binary_directory)
        binary_file_path = File.join(
          binary_file_directory, binary_file_name
        )

        mkdir_p installation_directory
        cp binary_file_path, installation_directory
      end

      private

      def platform
        Gem::Platform.local
      end

      def platform_os_name
        platform_os_names[platform.os.to_sym]
      end

      def platform_cpu_name
        platform_cpu_names[platform.cpu.to_sym]
      end

      def resolved_type
        type.is_a?(Hash) ? type[platform.os.to_sym].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

11 entries across 11 versions & 1 rubygems

Version Path
rake_dependencies-3.6.0.pre.4 lib/rake_dependencies/tasks/install.rb
rake_dependencies-3.6.0.pre.3 lib/rake_dependencies/tasks/install.rb
rake_dependencies-3.6.0.pre.2 lib/rake_dependencies/tasks/install.rb
rake_dependencies-3.6.0.pre.1 lib/rake_dependencies/tasks/install.rb
rake_dependencies-3.5.0 lib/rake_dependencies/tasks/install.rb
rake_dependencies-3.4.0.pre.1 lib/rake_dependencies/tasks/install.rb
rake_dependencies-3.3.0 lib/rake_dependencies/tasks/install.rb
rake_dependencies-3.2.0.pre.7 lib/rake_dependencies/tasks/install.rb
rake_dependencies-3.2.0.pre.6 lib/rake_dependencies/tasks/install.rb
rake_dependencies-3.2.0.pre.5 lib/rake_dependencies/tasks/install.rb
rake_dependencies-3.2.0.pre.4 lib/rake_dependencies/tasks/install.rb