class GemMirror::VersionsFile

The VersionsFile class acts as a small Ruby wrapper around the RubyGems file that contains all Gems and their associated versions.

@!attribute [r] versions

@return [Array]

@!attribute [r] versions_hash

@return [Hash]

Attributes

versions[R]
versions_hash[R]

Public Class Methods

load(content) click to toggle source

Reads the versions file from the specified String.

@param [String] content @return [GemMirror::VersionsFile]

   # File lib/gem_mirror/versions_file.rb
22 def self.load(content)
23   buffer   = StringIO.new(content)
24   reader   = Zlib::GzipReader.new(buffer)
25   instance = new(Marshal.load(reader.read))
26 
27   reader.close
28 
29   instance
30 end
new(versions) click to toggle source

@param [Array] versions

   # File lib/gem_mirror/versions_file.rb
35 def initialize(versions)
36   @versions      = versions
37   @versions_hash = create_versions_hash
38 end

Public Instance Methods

create_versions_hash() click to toggle source

Creates a Hash based on the Array containing all versions. This Hash is used to more easily (and faster) iterate over all the gems/versions.

@return [Hash]

   # File lib/gem_mirror/versions_file.rb
46 def create_versions_hash
47   hash = Hash.new { |h, k| h[k] = [] }
48 
49   versions.each do |version|
50     hash[version[0]] << version
51   end
52 
53   hash
54 end
versions_for(gem) click to toggle source

Returns an Array containing all the available versions for a Gem.

@param [String] gem @return [Array]

   # File lib/gem_mirror/versions_file.rb
62 def versions_for(gem)
63   versions_hash[gem].map { |version| version[1] }
64 end