Class: Gem::Install

Inherits:
Object show all
Defined in:
opal/stdlib/nodejs/rubygems.rb

Instance Method Summary collapse

Constructor Details

#initialize(name, version) ⇒ Install

Returns a new instance of Install



5
6
7
8
# File 'opal/stdlib/nodejs/rubygems.rb', line 5

def initialize(name, version)
  @name = name
  @version = version
end

Instance Method Details

#curl(url) ⇒ Object



49
50
51
# File 'opal/stdlib/nodejs/rubygems.rb', line 49

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

#full_nameObject



20
21
22
# File 'opal/stdlib/nodejs/rubygems.rb', line 20

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

#gem_homeObject



24
25
26
# File 'opal/stdlib/nodejs/rubygems.rb', line 24

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

#gems_dirObject



28
29
30
# File 'opal/stdlib/nodejs/rubygems.rb', line 28

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

#latest_version(name) ⇒ Object



14
15
16
17
18
# File 'opal/stdlib/nodejs/rubygems.rb', line 14

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

#performObject



36
37
38
39
40
41
42
43
44
45
46
47
# File 'opal/stdlib/nodejs/rubygems.rb', line 36

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

#specs_dirObject



32
33
34
# File 'opal/stdlib/nodejs/rubygems.rb', line 32

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

#versionObject



10
11
12
# File 'opal/stdlib/nodejs/rubygems.rb', line 10

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