Sha256: 5efaae123bdd0c438e187faa29bd9a6da54a3143e1894f72056a19443cc250be

Contents?: true

Size: 1.44 KB

Versions: 46

Compression:

Stored size: 1.44 KB

Contents

require 'json'

module Gem
  class Install
    def initialize(name, version)
      @name = name
      @version = version
    end

    def version
      @version ||= latest_version(name)
    end

    def latest_version(name)
      command = curl("https://rubygems.org/api/v1/versions/#{name}.json")
      versions = JSON.parse system(command)
      versions.first['number']
    end

    def full_name
      "#{name}-#{version}"
    end

    def gem_home
      ENV['HOME']+'/.opal-node/opal-gems/#{RUBY_ENGINE_VERSION}'
    end

    def gems_dir
      File.join(gem_home, :gems)
    end

    def specs_dir
      File.join(gem_home, :specs)
    end

    def perform
      gem_dir = File.join(gems_dir, full_name)
      spec_dir = File.join(specs_dir, full_name+'.yml')
      system "mkdir -p #{gem_dir} #{spec_dir}"

      Dir.chdir gem_dir do
        system curl("https://rubygems.org/downloads/#{name}-#{version}.gem") + '| tar -xv'
        system "gunzip metadata.gz --stdout > #{specs_dir}/#{full_name}.yml"
        system "gunzip data.tar.gz"
        system "tar -xvf data.tar"
      end
    end

    def curl url
      "curl -L #{url}"
    end
  end
end

command = ARGV.shift
case command
when 'install'
  name = ARGV.shift
  if ARGV.include? '-v'
    version = ARGV[ ARGV.index('-v')+1 ]
  else
    version = nil
  end
  install = Gem::Install.new(name, version)
  install.perform
else
  raise NotImplementedError, "sorry, the #{command.inspect} is not implemented."
end

Version data entries

46 entries across 46 versions & 3 rubygems

Version Path
opal-0.7.0.rc1 stdlib/nodejs/rubygems.rb
opal-0.7.0.beta3 stdlib/nodejs/rubygems.rb
opal-0.7.0.beta2 stdlib/nodejs/rubygems.rb
opal-cj-0.7.0.beta2 stdlib/nodejs/rubygems.rb
opal-cj-0.7.0.beta1 stdlib/nodejs/rubygems.rb
opal-0.7.0.beta1 stdlib/nodejs/rubygems.rb