Sha256: 53953f16a3940eb813aca1a0dc1c2515e06245e64fad45b2c08a7cf7e7a0e063

Contents?: true

Size: 1.6 KB

Versions: 2

Compression:

Stored size: 1.6 KB

Contents

# Usage:
#
#   Lambdagem::Extract::Ruby.new("2.5.0",
#     s3: "lambdagems",
#     build_root: cache_area, # defaults to /tmp/lambdagem
#     dest: cache_area, # defaults to . (project_root)
#   ).run
#
module Lambdagem::Extract
  class Ruby < Base
    class NotFound < RuntimeError; end

    def run
      puts "Looking for #{full_ruby_name} in S3 bucket: #{@options[:s3]}"
      clean_downloads(:rubies) if @options[:clean]
      tarball_path = download_ruby
      unpack_tarball(tarball_path)
    end

    def download_ruby
      url = ruby_url
      tarball_dest = download_file(url, download_path(File.basename(url)))
      unless tarball_dest
        message = "Url: #{url} not found"
        if @options[:exit_on_error]
          puts message
          # exit # TODO: ADD BACK IN
        else
          raise NotFound.new(message)
        end
      end
      puts "Tarball downloaded to: #{tarball_dest}"
      tarball_dest
    end

    def download_path(filename)
      "#{@build_root}/downloads/rubies/#{filename}"
    end

    # If only the ruby version is given, then append ruby- in front. Otherwise
    # leave alone.
    #
    # Example:
    #
    #    2.5.0           -> ruby-2.5.0-linux-x86_64.tgz
    #    ruby-2.5.0      -> ruby-2.5.0-linux-x86_64.tgz
    #    test-ruby-2.5.0 -> test-ruby-2.5.0-linux-x86_64.tgz
    def full_ruby_name
      md = @name.match(/^(\d+\.\d+\.\d+)$/)
      if md
        ruby_version = md[1]
        "ruby-#{ruby_version}-linux-x86_64.tgz"
      else
        "#{@name}-linux-x86_64.tgz"
      end
    end

    def ruby_url
      "#{lambdagems_url}/rubies/#{full_ruby_name}"
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
jets-0.5.2 vendor/lambdagem/lib/lambdagem/extract/ruby.rb
jets-0.5.1 vendor/lambdagem/lib/lambdagem/extract/ruby.rb