Class: Gem::Installer

Inherits:
Object
  • Object
show all
Defined in:
lib/rubygems/precompiled.rb

Defined Under Namespace

Classes: BaseCache, FileCache, HttpCache

Constant Summary collapse

GemCache =
{
  'file' => FileCache,
  'http' => HttpCache
}.freeze

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.precompiled_cachesObject

Private: A list of precompiled cache root URLs loaded from the rubyges configuration file

Returns Array of BaseCache subclasses



75
76
77
78
79
80
# File 'lib/rubygems/precompiled.rb', line 75

def self.precompiled_caches
  @@caches ||= [Gem.configuration['precompiled_cache']].flatten.compact.map do |cache_root|
    cache_root = URI.parse(cache_root)
    GemCache[cache_root.scheme].new(cache_root)
  end
end

Instance Method Details

#build_extensions_with_cacheObject Also known as: build_extensions



82
83
84
85
86
87
88
89
90
91
92
93
# File 'lib/rubygems/precompiled.rb', line 82

def build_extensions_with_cache
  cache = Gem::Installer.precompiled_caches.find { |cache| cache.contains?(@spec) }

  if cache
    puts "Loading native extension from cache"
    cache.retrieve(@spec) do |path|
      overlay_tarball(path)
    end
  else
    build_extensions_without_cache
  end
end

#overlay_tarball(tarball) ⇒ Object

 Private: Extracts a .tar.gz file on-top of the gem’s installation directory



99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
# File 'lib/rubygems/precompiled.rb', line 99

def overlay_tarball(tarball)
  Zlib::GzipReader.open(tarball) do |gzip_io|
    Gem::Package::TarReader.new(gzip_io) do |tar|
      tar.each do |entry|
        target_path = File.join(gem_dir, entry.full_name)
        if entry.directory?
          FileUtils.mkdir_p(target_path)
        elsif entry.file?
          FileUtils.mkdir_p(File.dirname(target_path))
          File.open(target_path, "w") do |f|
            f.write entry.read(1024*1024) until entry.eof?
          end
        end
        entry.close
      end
    end
  end
end