In Files

  • rubygems/source/local.rb

Class/Module Index [+]

Quicksearch

Gem::Source::Local

Public Class Methods

new() click to toggle source
 
               # File rubygems/source/local.rb, line 4
def initialize
  @uri = nil
end
            

Public Instance Methods

<=>(other) click to toggle source

Local sorts before Gem::Source and after Gem::Source::Installed

 
               # File rubygems/source/local.rb, line 11
def <=> other
  case other
  when Gem::Source::Installed then
    -1
  when Gem::Source::Local then
    0
  when Gem::Source then
    1
  else
    nil
  end
end
            
download(spec, cache_dir=nil) click to toggle source
 
               # File rubygems/source/local.rb, line 103
def download(spec, cache_dir=nil)
  load_specs :complete

  @specs.each do |name, data|
    return data[0] if data[1].spec == spec
  end

  raise Gem::Exception, "Unable to find file for '#{spec.full_name}'"
end
            
fetch_spec(name) click to toggle source
 
               # File rubygems/source/local.rb, line 93
def fetch_spec(name)
  load_specs :complete

  if data = @specs[name]
    data.last.spec
  else
    raise Gem::Exception, "Unable to find spec for '#{name}'"
  end
end
            
find_gem(gem_name, version=Gem::Requirement.default, prerelease=false) click to toggle source
 
               # File rubygems/source/local.rb, line 70
def find_gem(gem_name, version=Gem::Requirement.default,
             prerelease=false)
  load_specs :complete

  found = []

  @specs.each do |n, data|
    if n.name == gem_name
      s = data[1].spec

      if version.satisfied_by?(s.version)
        if prerelease
          found << s
        elsif !s.version.prerelease?
          found << s
        end
      end
    end
  end

  found.sort_by { |s| s.version }.last
end
            
load_specs(type) click to toggle source
 
               # File rubygems/source/local.rb, line 28
def load_specs(type)
  names = []

  @specs = {}

  Dir["*.gem"].each do |file|
    begin
      pkg = Gem::Package.new(file)
    rescue SystemCallError, Gem::Package::FormatError
      # ignore
    else
      tup = pkg.spec.name_tuple
      @specs[tup] = [File.expand_path(file), pkg]

      case type
      when :released
        unless pkg.spec.version.prerelease?
          names << pkg.spec.name_tuple
        end
      when :prerelease
        if pkg.spec.version.prerelease?
          names << pkg.spec.name_tuple
        end
      when :latest
        tup = pkg.spec.name_tuple

        cur = names.find { |x| x.name == tup.name }
        if !cur
          names << tup
        elsif cur.version < tup.version
          names.delete cur
          names << tup
        end
      else
        names << pkg.spec.name_tuple
      end
    end
  end

  names
end
            

Commenting is here to help enhance the documentation. For example, code samples, or clarification of the documentation.

If you have questions about Ruby or the documentation, please post to one of the Ruby mailing lists. You will get better, faster, help that way.

If you wish to post a correction of the docs, please do so, but also file bug report so that it can be corrected for the next release. Thank you.

If you want to help improve the Ruby documentation, please see Improve the docs, or visit Documenting-ruby.org.

blog comments powered by Disqus