Sha256: fc2e80d16cde2a660c5883eb2e1fdd5f46b1bd0bc2bf191d0c9c59aab3a30439

Contents?: true

Size: 1.83 KB

Versions: 3

Compression:

Stored size: 1.83 KB

Contents

class FasterRubyGems
  def self.gem_prelude_paths
    # note: the RUBY_VERSION[0..2] thing below fails for 1.9...
    raise 'bad version' if RUBY_VERSION[0..2] > '1.8'
    require 'rbconfig'

    gem_paths = []
    # add the default gem path
     
    gem_paths << Config::CONFIG['libdir'] + '/ruby/gems/' + RUBY_VERSION[0..2] + '/gems'

    # add ~/.gem
    gem_paths << File.expand_path('~') + '/.gem/ruby/' + RUBY_VERSION[0..2] + '/gems'

    # add ENV['GEM_PATH'] if it exists
    if ENV['GEM_PATH']
      gem_paths = ENV['GEM_PATH'].split(File::PATH_SEPARATOR).collect{|path| path + '/gems'} 
    end

    all_gems = []

    for gem_path in gem_paths.flatten do
      all_gems << Dir.glob(gem_path + '/*')
    end
    all_gems.flatten!
    all_gems = all_gems.sort_by{|gem| gem.split('-')[-1].split('.').map{|n| n.to_i}} # 0.10.0 > 0.9.0 so straight sort won't work for us
    all_gems.reverse!

    already_loaded_gems = {}

    prelude_paths = []

    for gem in all_gems do

      version = gem.split('-')[-1]
      if version =~ /\d+\.\d+\.\d+/
        name = gem.split('-')[0..-2]
      else
        gem =~ /(.*)(\d+\.\d+\.\d+).*$/ # like abc-1.2.3-mswin32-60 or what not
        version = $2
        name = $1
        next unless version # a few oddities like rbfind-1.1
      end

      if(!already_loaded_gems[name])
        already_loaded_gems[name] = true
        if File.directory? gem + '/lib'
          prelude_paths << gem + '/lib'
        else
          # unfortunately a few gems load from, say gem/something_not_lib/gemname.rb
          for dir in Dir.glob(gem + '/*') do
            if File.directory? dir
              $: << dir
              # if anybody wants anything lower than that, let me know
            end
          end
        end
      end

    end
    prelude_paths
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
faster_rubygems-0.2.1 lib/faster_rubygems_lib.rb
faster_rubygems-0.2.0 lib/faster_rubygems_lib.rb
faster_rubygems-0.1.0 lib/faster_rubygems_lib.rb