Skip to content

Commit

Permalink
Moved source_local.rb to source/local.rb
Browse files Browse the repository at this point in the history
  • Loading branch information
drbrain committed Apr 4, 2013
1 parent 05c705f commit 43a85d3
Show file tree
Hide file tree
Showing 5 changed files with 117 additions and 111 deletions.
1 change: 1 addition & 0 deletions Manifest.txt
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ lib/rubygems/security/trust_dir.rb
lib/rubygems/server.rb
lib/rubygems/source.rb
lib/rubygems/source/installed.rb
lib/rubygems/source/local.rb
lib/rubygems/source_list.rb
lib/rubygems/source_local.rb
lib/rubygems/source_specific_file.rb
Expand Down
2 changes: 1 addition & 1 deletion lib/rubygems/dependency_installer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
require 'rubygems/installer'
require 'rubygems/spec_fetcher'
require 'rubygems/user_interaction'
require 'rubygems/source_local'
require 'rubygems/source/local'
require 'rubygems/source_specific_file'
require 'rubygems/available_set'

Expand Down
112 changes: 112 additions & 0 deletions lib/rubygems/source/local.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
require 'rubygems/source'

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

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

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

def inspect # :nodoc:
"#<%s specs: %p>" % [self.class, @specs.keys]
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
111 changes: 2 additions & 109 deletions lib/rubygems/source_local.rb
Original file line number Diff line number Diff line change
@@ -1,112 +1,5 @@
require 'rubygems/source'
require 'rubygems/source_local'

class Gem::Source::Local < Gem::Source
def initialize
@uri = nil
end
# TODO warn upon require, this file is deprecated.

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

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

def inspect # :nodoc:
"#<%s specs: %p>" % [self.class, @specs.keys]
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
2 changes: 1 addition & 1 deletion test/rubygems/test_gem_source_local.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
require 'rubygems/test_case'
require 'rubygems/source_local'
require 'rubygems/source/local'

require 'fileutils'

Expand Down

0 comments on commit 43a85d3

Please sign in to comment.