Skip to content

Commit

Permalink
+ Moved lots of stuff from rubygems.rb. (steveklabnik)
Browse files Browse the repository at this point in the history
  • Loading branch information
zenspider committed Dec 23, 2011
1 parent 9c892e7 commit 3714bed
Show file tree
Hide file tree
Showing 6 changed files with 123 additions and 103 deletions.
1 change: 1 addition & 0 deletions Manifest.txt
Expand Up @@ -48,6 +48,7 @@ lib/rubygems/commands/uninstall_command.rb
lib/rubygems/commands/unpack_command.rb
lib/rubygems/commands/update_command.rb
lib/rubygems/commands/which_command.rb
lib/rubygems/compatability.rb
lib/rubygems/config_file.rb
lib/rubygems/custom_require.rb
lib/rubygems/defaults.rb
Expand Down
81 changes: 7 additions & 74 deletions lib/rubygems.rb
Expand Up @@ -95,87 +95,20 @@
#
# -The RubyGems Team

# Ruby 1.9.x has introduced some things that are awkward, and we need to
# support them, so we define some constants to use later.
module Gem
QUICKLOADER_SUCKAGE = RUBY_VERSION =~ /^1\.9\.1/
GEM_PRELUDE_SUCKAGE = RUBY_VERSION =~ /^1\.9\.2/
end

# Gem::QuickLoader exists in the gem prelude code in ruby 1.9.2 itself.
# We gotta get rid of it if it's there, before we do anything else.
#
# REFACTOR: Pulling this kind of thing out into some sort of file with
# all of the hacks would be a Good Idea.
if Gem::GEM_PRELUDE_SUCKAGE and defined?(Gem::QuickLoader) then
Gem::QuickLoader.remove

$LOADED_FEATURES.delete Gem::QuickLoader.path_to_full_rubygems_library

if $LOADED_FEATURES.any? do |path| path.end_with? '/rubygems.rb' end then
# TODO path does not exist here
raise LoadError, "another rubygems is already loaded from #{path}"
end

class << Gem
remove_method :try_activate if Gem.respond_to?(:try_activate, true)
end
end

require 'rubygems/defaults'
require 'rbconfig'
require "rubygems/deprecate"


module Gem
VERSION = '1.8.10'
DEFAULT_HOST = "https://rubygems.org"

##
# Raised when RubyGems is unable to load or activate a gem. Contains the
# name and version requirements of the gem that either conflicts with
# already activated gems or that RubyGems is otherwise unable to activate.

class LoadError < ::LoadError
# Name of gem
attr_accessor :name

# Version requirement of gem
attr_accessor :requirement
end

# REFACTOR: Things like stopdoc tend to indicate that something might not
# be particularly well factored, and in this case, this is true. We're
# sort of patching over weirdness with RbConfig. This should be pulled
# out into some sort of file with all the compatibility hacks in it.

# :stopdoc:

RubyGemsVersion = VERSION

RbConfigPriorities = %w[
EXEEXT RUBY_SO_NAME arch bindir datadir libdir ruby_install_name
ruby_version rubylibprefix sitedir sitelibdir vendordir vendorlibdir
]

unless defined?(ConfigMap)
##
# Configuration settings from ::RbConfig
ConfigMap = Hash.new do |cm, key|
cm[key] = RbConfig::CONFIG[key.to_s]
end
else
RbConfigPriorities.each do |key|
ConfigMap[key.to_sym] = RbConfig::CONFIG[key]
end
end
end

RubyGemsPackageVersion = VERSION
require 'rubygems/defaults'
require 'rubygems/deprecate'
require 'rubygems/compatability'
require 'rubygems/errors'

module Gem
RUBYGEMS_DIR = File.dirname File.expand_path(__FILE__)

# :startdoc:


##
# An Array of Regexps that match windows ruby platforms.

Expand Down
50 changes: 50 additions & 0 deletions lib/rubygems/compatability.rb
@@ -0,0 +1,50 @@
# This file contains all sorts of little compatability hacks that we've
# had to introduce over the years. Quarantining them into one file helps
# us know when we can get rid of them.

# Ruby 1.9.x has introduced some things that are awkward, and we need to
# support them, so we define some constants to use later.
module Gem
QUICKLOADER_SUCKAGE = RUBY_VERSION =~ /^1\.9\.1/
GEM_PRELUDE_SUCKAGE = RUBY_VERSION =~ /^1\.9\.2/
end

# Gem::QuickLoader exists in the gem prelude code in ruby 1.9.2 itself.
# We gotta get rid of it if it's there, before we do anything else.
if Gem::GEM_PRELUDE_SUCKAGE and defined?(Gem::QuickLoader) then
Gem::QuickLoader.remove

$LOADED_FEATURES.delete Gem::QuickLoader.path_to_full_rubygems_library

if $LOADED_FEATURES.any? do |path| path.end_with? '/rubygems.rb' end then
# TODO path does not exist here
raise LoadError, "another rubygems is already loaded from #{path}"
end

class << Gem
remove_method :try_activate if Gem.respond_to?(:try_activate, true)
end
end

module Gem
RubyGemsVersion = VERSION

RbConfigPriorities = %w[
EXEEXT RUBY_SO_NAME arch bindir datadir libdir ruby_install_name
ruby_version rubylibprefix sitedir sitelibdir vendordir vendorlibdir
]

unless defined?(ConfigMap)
##
# Configuration settings from ::RbConfig
ConfigMap = Hash.new do |cm, key|
cm[key] = RbConfig::CONFIG[key.to_s]
end
else
RbConfigPriorities.each do |key|
ConfigMap[key.to_sym] = RbConfig::CONFIG[key]
end
end

RubyGemsPackageVersion = VERSION
end
3 changes: 1 addition & 2 deletions lib/rubygems/defaults.rb
@@ -1,6 +1,5 @@
module Gem

# TODO: move this whole file back into rubygems.rb
DEFAULT_HOST = "https://rubygems.org"

@post_install_hooks ||= []
@done_installing_hooks ||= []
Expand Down
89 changes: 63 additions & 26 deletions lib/rubygems/errors.rb
@@ -1,36 +1,73 @@
class Gem::ErrorReason; end # TODO: remove, unnecessary superclass

# TODO move to lib/rubygems/platform_mismatch.rb
# TODO write tests
#--
# Generated when a gem is found that isn't usable on the current platform.
##
# This file contains all the various exceptions and other errors that are used
# inside of RubyGems.
#
class Gem::PlatformMismatch < Gem::ErrorReason
# DOC: Confirm _all_

attr_reader :name
attr_reader :version
attr_reader :platforms
module Gem
##
# Raised when RubyGems is unable to load or activate a gem. Contains the
# name and version requirements of the gem that either conflicts with
# already activated gems or that RubyGems is otherwise unable to activate.

def initialize(name, version)
@name = name
@version = version
@platforms = []
end
class LoadError < ::LoadError
# Name of gem
attr_accessor :name

def add_platform(platform)
@platforms << platform
# Version requirement of gem
attr_accessor :requirement
end

#--
# Replace only "platforms", remove duplicate strings
def wordy
prefix = "Found #{@name} (#{@version})"
# FIX: does this need to exist? The subclass is the only other reference
# I can find.
class ErrorReason; end

# Generated when trying to lookup a gem to indicate that the gem
# was found, but that it isn't usable on the current platform.
#
# fetch and install read these and report them to the user to aid
# in figuring out why a gem couldn't be installed.
#
class PlatformMismatch < ErrorReason

##
# the name of the gem
attr_reader :name

##
# the version
attr_reader :version

##
# The platforms that are mismatched
attr_reader :platforms

if @platforms.size == 1
"#{prefix}, but was for platform #{@platforms[0]}"
else
"#{prefix}, but was for platforms #{@platforms.join(' ,')}"
def initialize(name, version)
@name = name
@version = version
@platforms = []
end

##
# append a platform to the list of mismatched platforms.
#
# Platforms are added via this instead of injected via the constructor
# so that we can loop over a list of mismatches and just add them rather
# than perform some kind of calculation mismatch summary before creation.
def add_platform(platform)
@platforms << platform
end
end

##
# A wordy description of the error.
def wordy
prefix = "Found #{@name} (#{@version})"

"Found %s (%), but was for platform%s %s" %
[@name,
@version,
@platforms.size == 1 ? 's' : '',
@platforms.join(' ,')]
end
end
end
2 changes: 1 addition & 1 deletion lib/rubygems/test_case.rb
Expand Up @@ -18,7 +18,7 @@
gem 'json'
end

require "rubygems/deprecate"
require 'rubygems/deprecate'
require 'minitest/autorun'
require 'fileutils'
require 'tmpdir'
Expand Down

0 comments on commit 3714bed

Please sign in to comment.