Sha256: 4a8709a1c2726a522902a2d60ef815cafc11f6751082b6688acdf7e3a8423da9

Contents?: true

Size: 1.88 KB

Versions: 22

Compression:

Stored size: 1.88 KB

Contents

require 'rubygems/source'

class Gem::Source::Local < Gem::Source
  def initialize
    @uri = nil
  end

  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

  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

  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

  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
end

Version data entries

22 entries across 22 versions & 1 rubygems

Version Path
rubygems-update-2.0.17 lib/rubygems/source_local.rb
rubygems-update-2.0.16 lib/rubygems/source_local.rb
rubygems-update-2.0.15 lib/rubygems/source_local.rb
rubygems-update-2.0.14 lib/rubygems/source_local.rb
rubygems-update-2.0.13 lib/rubygems/source_local.rb
rubygems-update-2.0.12 lib/rubygems/source_local.rb
rubygems-update-2.0.11 lib/rubygems/source_local.rb
rubygems-update-2.0.10 lib/rubygems/source_local.rb
rubygems-update-2.0.9 lib/rubygems/source_local.rb
rubygems-update-2.0.8 lib/rubygems/source_local.rb
rubygems-update-2.0.7 lib/rubygems/source_local.rb
rubygems-update-2.0.6 lib/rubygems/source_local.rb
rubygems-update-2.0.5 lib/rubygems/source_local.rb
rubygems-update-2.0.4 lib/rubygems/source_local.rb
rubygems-update-2.0.3 lib/rubygems/source_local.rb
rubygems-update-2.0.2 lib/rubygems/source_local.rb
rubygems-update-2.0.0 lib/rubygems/source_local.rb
rubygems-update-2.0.0.rc.2 lib/rubygems/source_local.rb
rubygems-update-2.0.0.rc.1 lib/rubygems/source_local.rb
rubygems-update-2.0.0.preview2.2 lib/rubygems/source_local.rb