summaryrefslogtreecommitdiff
path: root/tool/gem-unpack.rb
blob: cb05719463f27c4eefd617b6dbecc447a1a80a8c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
require 'fileutils'
require 'rubygems'
require 'rubygems/package'

# This library is used by "make extract-gems" to
# unpack bundled gem files.

def Gem.unpack(file, dir = nil)
  pkg = Gem::Package.new(file)
  spec = pkg.spec
  target = spec.full_name
  target = File.join(dir, target) if dir
  pkg.extract_files target
  spec_file = File.join(target, "#{spec.name}-#{spec.version}.gemspec")
  open(spec_file, 'wb') do |f|
    f.print spec.to_ruby
  end
  puts "Unpacked #{file}"
end