Skip to content

Commit

Permalink
Privatize kernel methods, expose Kernel extensions to RDoc.
Browse files Browse the repository at this point in the history
git-svn-id: svn+ssh://rubyforge.org/var/svn/rubygems/trunk@1905 3d4018f9-ac1a-0410-99e9-8a154d859a19
  • Loading branch information
drbrain committed Oct 25, 2008
1 parent a7cc102 commit 28aca90
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 21 deletions.
6 changes: 6 additions & 0 deletions ChangeLog
@@ -1,5 +1,11 @@
# -*- coding: utf-8 -*-

2008-10-25 Eric Hodel <drbrain@segment7.net>

* lib/rubygems.rb, lib/rubygems/custom_require.rb: Make kernel
methods private. Patch #20801 by Stefan Rusterholz. Also expose
our extensions to RDoc.

2008-10-10 Eric Hodel <drbrain@segment7.net>

* lib/rubygems/commands/unpack_command.rb: Silence PATH warning.
Expand Down
12 changes: 7 additions & 5 deletions lib/rubygems.rb
Expand Up @@ -43,12 +43,14 @@ module Kernel
#
# GEM_SKIP=libA:libB ruby -I../libA -I../libB ./mycode.rb

def gem(gem_name, *version_requirements)
def gem(gem_name, *version_requirements) # :doc:
skip_list = (ENV['GEM_SKIP'] || "").split(/:/)
raise Gem::LoadError, "skipping #{gem_name}" if skip_list.include? gem_name
Gem.activate(gem_name, *version_requirements)
end

private :gem

end

##
Expand Down Expand Up @@ -104,10 +106,10 @@ module Gem
@ruby = nil
@sources = []

@post_install_hooks = []
@post_uninstall_hooks = []
@pre_uninstall_hooks = []
@pre_install_hooks = []
@post_install_hooks ||= []
@post_uninstall_hooks ||= []
@pre_uninstall_hooks ||= []
@pre_install_hooks ||= []

##
# Activates an installed gem matching +gem+. The gem must satisfy
Expand Down
22 changes: 15 additions & 7 deletions lib/rubygems/custom_require.rb
Expand Up @@ -7,11 +7,15 @@
require 'rubygems'

module Kernel
alias gem_original_require require # :nodoc:

#
# We replace Ruby's require with our own, which is capable of
# loading gems on demand.
##
# The Kernel#require from before RubyGems was loaded.

alias gem_original_require require

##
# When RubyGems is required, Kernel#require is replaced with our own which
# is capable of loading gems on demand.
#
# When you call <tt>require 'x'</tt>, this is what happens:
# * If the file can be loaded from the existing Ruby loadpath, it
Expand All @@ -22,8 +26,8 @@ module Kernel
#
# The normal <tt>require</tt> functionality of returning false if
# that file has already been loaded is preserved.
#
def require(path) # :nodoc:

def require(path) # :doc:
gem_original_require path
rescue LoadError => load_error
if load_error.message =~ /#{Regexp.escape path}\z/ and
Expand All @@ -34,5 +38,9 @@ def require(path) # :nodoc:
raise load_error
end
end
end # module Kernel

private :require
private :gem_original_require

end

5 changes: 5 additions & 0 deletions lib/rubygems/defaults.rb
@@ -1,5 +1,10 @@
module Gem

@post_install_hooks ||= []
@post_uninstall_hooks ||= []
@pre_uninstall_hooks ||= []
@pre_install_hooks ||= []

##
# An Array of the default sources that come with RubyGems

Expand Down
42 changes: 33 additions & 9 deletions util/gem_prelude.rb
Expand Up @@ -24,14 +24,6 @@ module Gem
:ruby_install_name => RbConfig::CONFIG["ruby_install_name"]
}

def self.default_dir
if defined? RUBY_FRAMEWORK_VERSION
return File.join(File.dirname(ConfigMap[:sitedir]), "Gems")
else
File.join(ConfigMap[:libdir], 'ruby', 'gems', ConfigMap[:ruby_version])
end
end

def self.dir
@gem_home ||= nil
set_home(ENV['GEM_HOME'] || default_dir) unless @gem_home
Expand All @@ -48,7 +40,22 @@ def self.path
@gem_path
end

# Set the Gem home directory (as reported by +dir+).
def self.post_install(&hook)
@post_install_hooks << hook
end

def self.post_uninstall(&hook)
@post_uninstall_hooks << hook
end

def self.pre_install(&hook)
@pre_install_hooks << hook
end

def self.pre_uninstall(&hook)
@pre_uninstall_hooks << hook
end

def self.set_home(home)
@gem_home = home
ensure_gem_subdirectories(@gem_home)
Expand All @@ -68,8 +75,25 @@ def self.set_paths(gpaths)
def self.ensure_gem_subdirectories(path)
end

# Methods before this line will be removed when QuickLoader is replaced
# with the real RubyGems

GEM_PRELUDE_METHODS = Gem.methods(false)

require 'rubygems/defaults'

begin
require 'rubygems/defaults/operating_system'
rescue LoadError
end

if defined?(RUBY_ENGINE) then
begin
require 'rubygems/defaults/#{RUBY_ENGINE}'
rescue LoadError
end
end

module QuickLoader

def self.load_full_rubygems_library
Expand Down

0 comments on commit 28aca90

Please sign in to comment.