diff --git a/ChangeLog b/ChangeLog index 83532a58b4f8..234ec5f60936 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,11 @@ # -*- coding: utf-8 -*- +2008-10-25 Eric Hodel + + * 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 * lib/rubygems/commands/unpack_command.rb: Silence PATH warning. diff --git a/lib/rubygems.rb b/lib/rubygems.rb index 65a8d090074b..ef791e6e0462 100644 --- a/lib/rubygems.rb +++ b/lib/rubygems.rb @@ -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 ## @@ -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 diff --git a/lib/rubygems/custom_require.rb b/lib/rubygems/custom_require.rb index 90e6b539593d..78c7872b6fc5 100755 --- a/lib/rubygems/custom_require.rb +++ b/lib/rubygems/custom_require.rb @@ -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 require 'x', this is what happens: # * If the file can be loaded from the existing Ruby loadpath, it @@ -22,8 +26,8 @@ module Kernel # # The normal require 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 @@ -34,5 +38,9 @@ def require(path) # :nodoc: raise load_error end end -end # module Kernel + + private :require + private :gem_original_require + +end diff --git a/lib/rubygems/defaults.rb b/lib/rubygems/defaults.rb index 7eba0cb04913..c894bf41be34 100644 --- a/lib/rubygems/defaults.rb +++ b/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 diff --git a/util/gem_prelude.rb b/util/gem_prelude.rb index 28bbd8372fb8..b483a65b08b3 100644 --- a/util/gem_prelude.rb +++ b/util/gem_prelude.rb @@ -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 @@ -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) @@ -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