Sha256: 7f45c36ca9b810309d0f197f2292e2225791f83b7baf6422336021d14181fe6a

Contents?: true

Size: 1.77 KB

Versions: 74

Compression:

Stored size: 1.77 KB

Contents

# Usage:
#
#   Jets::Gems::Extract::Ruby.new("2.5.3",
#     downloads_root: cache_area, # defaults to /tmp/lambdagem
#     dest: cache_area, # defaults to . (project_root)
#   ).run
#
module Jets::Gems::Extract
  class Ruby < Base
    class NotFound < RuntimeError; end

    def run
      say "Looking for #{full_ruby_name}"
      clean_downloads(:rubies) if @options[:clean]
      zip_path = download_ruby
      unzip(zip_path)
    end

    def unzip(path)
      dest = "#{Jets.build_root}/stage/code/opt"
      say "Unpacking into #{dest}"
      FileUtils.mkdir_p(dest)
      # cd-ing dest unzips the files into that folder
      sh("cd #{dest} && unzip -qo #{path}")
      say("Ruby #{full_ruby_name} unziped at #{dest}", :debug)
    end

    def download_ruby
      url = ruby_url
      puts "download ruby url #{url}"
      tarball_dest = download_file(url, download_path(File.basename(url)))
      unless tarball_dest
        message = "Url: #{url} not found"
        if @options[:exit_on_error]
          say message
          exit
        else
          raise NotFound.new(message)
        end
      end
      say "Downloaded to: #{tarball_dest}"
      tarball_dest
    end

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

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

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

Version data entries

74 entries across 74 versions & 2 rubygems

Version Path
jets-gems-0.2.3 lib/jets/gems/extract/ruby.rb
jets-gems-0.2.2 lib/jets/gems/extract/ruby.rb
jets-gems-0.2.1 lib/jets/gems/extract/ruby.rb
jets-gems-0.2.0 lib/jets/gems/extract/ruby.rb
jets-gems-0.1.0 lib/jets/gems/extract/ruby.rb
jets-1.9.7 vendor/jets-gems/lib/jets/gems/extract/ruby.rb
jets-1.9.6 vendor/jets-gems/lib/jets/gems/extract/ruby.rb
jets-1.9.5 vendor/jets-gems/lib/jets/gems/extract/ruby.rb
jets-1.9.4 vendor/jets-gems/lib/jets/gems/extract/ruby.rb
jets-1.9.3 vendor/jets-gems/lib/jets/gems/extract/ruby.rb
jets-1.9.2 vendor/jets-gems/lib/jets/gems/extract/ruby.rb
jets-1.9.1 vendor/jets-gems/lib/jets/gems/extract/ruby.rb
jets-1.9.0 vendor/jets-gems/lib/jets/gems/extract/ruby.rb
jets-1.8.14 vendor/jets-gems/lib/jets/gems/extract/ruby.rb
jets-1.8.13 vendor/jets-gems/lib/jets/gems/extract/ruby.rb
jets-1.8.12 vendor/jets-gems/lib/jets/gems/extract/ruby.rb
jets-1.8.11 vendor/jets-gems/lib/jets/gems/extract/ruby.rb
jets-1.8.10 vendor/jets-gems/lib/jets/gems/extract/ruby.rb
jets-1.8.9 vendor/jets-gems/lib/jets/gems/extract/ruby.rb
jets-1.8.8 vendor/jets-gems/lib/jets/gems/extract/ruby.rb