[macruby-changes] [836] MacRuby/trunk/gem_prelude.rb
source_changes at macosforge.org
source_changes at macosforge.org
Fri Mar 6 15:30:14 PST 2009
Revision: 836
http://trac.macosforge.org/projects/ruby/changeset/836
Author: lsansonetti at apple.com
Date: 2009-03-06 15:30:14 -0800 (Fri, 06 Mar 2009)
Log Message:
-----------
imported new gem_prelude.rb from 1.9.1
Modified Paths:
--------------
MacRuby/trunk/gem_prelude.rb
Modified: MacRuby/trunk/gem_prelude.rb
===================================================================
--- MacRuby/trunk/gem_prelude.rb 2009-03-03 07:39:10 UTC (rev 835)
+++ MacRuby/trunk/gem_prelude.rb 2009-03-06 23:30:14 UTC (rev 836)
@@ -1,9 +1,11 @@
# depends on: array.rb dir.rb env.rb file.rb hash.rb module.rb regexp.rb
+# vim: filetype=ruby
+# THIS FILE WAS AUTOGENERATED, DO NOT EDIT
-# empty gem_prelude.rb
-#
-# p defined?(Gem)
-
+# NOTICE: Ruby is during initialization here.
+# * Encoding.default_external does not reflects -E.
+# * Should not expect Encoding.default_internal.
+# * Locale encoding is available.
if defined?(Gem) then
module Kernel
@@ -16,6 +18,9 @@
module Gem
+ class LoadError < ::LoadError
+ end
+
ConfigMap = {
:sitedir => RbConfig::CONFIG["sitedir"],
:ruby_version => RbConfig::CONFIG["ruby_version"],
@@ -28,73 +33,196 @@
:ruby_install_name => RbConfig::CONFIG["ruby_install_name"]
}
- class << self
+ def self.dir
+ @gem_home ||= nil
+ set_home(ENV['GEM_HOME'] || default_dir) unless @gem_home
+ @gem_home
+ end
- def 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
+ def self.path
+ @gem_path ||= nil
+ unless @gem_path
+ paths = [ENV['GEM_PATH']]
+ paths << APPLE_GEM_HOME if defined? APPLE_GEM_HOME
+ set_paths(paths.compact.join(File::PATH_SEPARATOR))
end
+ @gem_path
+ end
- def dir
- @gem_home ||= nil
- set_home(ENV['GEM_HOME'] || default_dir) unless @gem_home
- @gem_home
+ 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)
+ end
+
+ def self.set_paths(gpaths)
+ if gpaths
+ @gem_path = gpaths.split(File::PATH_SEPARATOR)
+ @gem_path << Gem.dir
+ else
+ @gem_path = [Gem.dir]
end
+ @gem_path.uniq!
+ @gem_path.each do |gp| ensure_gem_subdirectories(gp) end
+ end
- def path
- @gem_path ||= nil
- unless @gem_path
- paths = [ENV['GEM_PATH']]
- paths << APPLE_GEM_HOME if defined? APPLE_GEM_HOME
- set_paths(paths.compact.join(File::PATH_SEPARATOR))
- end
- @gem_path
+ def self.ensure_gem_subdirectories(path)
+ end
+
+
+ @post_install_hooks ||= []
+ @post_uninstall_hooks ||= []
+ @pre_uninstall_hooks ||= []
+ @pre_install_hooks ||= []
+
+ ##
+ # An Array of the default sources that come with RubyGems
+
+ def self.default_sources
+ %w[http://gems.rubyforge.org/]
+ end
+
+ ##
+ # Default home directory path to be used if an alternate value is not
+ # specified in the environment
+
+ def self.default_dir
+ if defined? RUBY_FRAMEWORK_VERSION then
+ File.join File.dirname(ConfigMap[:sitedir]), 'Gems',
+ ConfigMap[:ruby_version]
+ elsif RUBY_VERSION > '1.9' then
+ File.join(ConfigMap[:libdir], ConfigMap[:ruby_install_name], 'gems',
+ ConfigMap[:ruby_version])
+ else
+ File.join(ConfigMap[:libdir], ruby_engine, 'gems',
+ ConfigMap[:ruby_version])
end
+ end
+
+ ##
+ # Path for gems in the user's home directory
+
+ def self.user_dir
+ File.join(Gem.user_home, '.gem', ruby_engine,
+ ConfigMap[:ruby_version])
+ end
+
+ ##
+ # Default gem load path
+
+ def self.default_path
+ [user_dir, default_dir]
+ end
+
+ ##
+ # Deduce Ruby's --program-prefix and --program-suffix from its install name
+
+ def self.default_exec_format
+ baseruby = ConfigMap[:BASERUBY] || 'ruby'
+ ConfigMap[:RUBY_INSTALL_NAME].sub(baseruby, '%s') rescue '%s'
+ end
+
+ ##
+ # The default directory for binaries
+
+ def self.default_bindir
+ if defined? RUBY_FRAMEWORK_VERSION then # mac framework support
+ '/usr/bin'
+ else # generic install
+ ConfigMap[:bindir]
+ end
+ end
+
+ ##
+ # The default system-wide source info cache directory
+
+ def self.default_system_source_cache_dir
+ File.join Gem.dir, 'source_cache'
+ end
+
+ ##
+ # The default user-specific source info cache directory
+
+ def self.default_user_source_cache_dir
+ File.join Gem.user_home, '.gem', 'source_cache'
+ end
+
+ ##
+ # A wrapper around RUBY_ENGINE const that may not be defined
+
+ def self.ruby_engine
+ if defined? RUBY_ENGINE then
+ RUBY_ENGINE
+ else
+ 'ruby'
+ end
+ end
+
+
- # Set the Gem home directory (as reported by +dir+).
- def set_home(home)
- @gem_home = home
- ensure_gem_subdirectories(@gem_home)
+ # Methods before this line will be removed when QuickLoader is replaced
+ # with the real RubyGems
+
+ GEM_PRELUDE_METHODS = Gem.methods(false)
+
+ begin
+ verbose, debug = $VERBOSE, $DEBUG
+ $DEBUG = $VERBOSE = nil
+
+ begin
+ require 'rubygems/defaults/operating_system'
+ rescue ::LoadError
end
- def set_paths(gpaths)
- if gpaths
- @gem_path = gpaths.split(File::PATH_SEPARATOR)
- @gem_path << Gem.dir
- else
- @gem_path = [Gem.dir]
+ if defined?(RUBY_ENGINE) then
+ begin
+ require "rubygems/defaults/#{RUBY_ENGINE}"
+ rescue ::LoadError
end
- @gem_path.uniq!
- @gem_path.each do |gp| ensure_gem_subdirectories(gp) end
end
-
- def ensure_gem_subdirectories(path)
- end
-
+ ensure
+ $VERBOSE, $DEBUG = verbose, debug
end
module QuickLoader
- class << self
- def load_full_rubygems_library
- class << Gem
- Gem.methods(false).each do |method_name|
- undef_method method_name
- end
- end
+ @loaded_full_rubygems_library = false
- Kernel.module_eval do
- undef_method :gem if method_defined? :gem
+ def self.load_full_rubygems_library
+ return if @loaded_full_rubygems_library
+
+ @loaded_full_rubygems_library = true
+
+ class << Gem
+ Gem::GEM_PRELUDE_METHODS.each do |method_name|
+ undef_method method_name
end
+ end
- $".delete File.join(Gem::ConfigMap[:libdir], 'ruby',
- Gem::ConfigMap[:ruby_version], 'rubygems.rb')
+ Kernel.module_eval do
+ undef_method :gem if method_defined? :gem
+ end
- require 'rubygems'
- end
+ $".delete File.join(Gem::ConfigMap[:libdir],
+ Gem::ConfigMap[:ruby_install_name],
+ Gem::ConfigMap[:ruby_version], 'rubygems.rb')
+
+ require 'rubygems'
end
GemPaths = {}
@@ -103,7 +231,7 @@
def push_gem_version_on_load_path(gem_name, *version_requirements)
if version_requirements.empty?
unless GemPaths.has_key?(gem_name)
- raise LoadError.new("Could not find RubyGem #{gem_name} (>= 0)\n")
+ raise Gem::LoadError.new("Could not find RubyGem #{gem_name} (>= 0)\n")
end
# highest version gems already active
@@ -119,7 +247,7 @@
if requirement == ">" || requirement == ">="
if (GemVersions[gem_name] <=> Gem.calculate_integers_for_gem_version(version)) >= 0
- return false
+ return false
end
elsif requirement == "~>"
loaded_version = GemVersions[gem_name]
@@ -167,12 +295,16 @@
require_paths = []
- GemPaths.values.each do |path|
- if File.exist?(File.join(path, ".require_paths"))
- require_paths.concat(File.read(File.join(path, ".require_paths")).split.map {|require_path| File.join(path, require_path)})
+ GemPaths.each_value do |path|
+ if File.exist?(file = File.join(path, ".require_paths")) then
+ paths = File.read(file).split.map do |require_path|
+ File.join path, require_path
+ end
+
+ require_paths.concat paths
else
- require_paths << File.join(path, "bin") if File.exist?(File.join(path, "bin"))
- require_paths << File.join(path, "lib") if File.exist?(File.join(path, "lib"))
+ require_paths << file if File.exist?(file = File.join(path, "bin"))
+ require_paths << file if File.exist?(file = File.join(path, "lib"))
end
end
@@ -208,7 +340,7 @@
begin
Gem.push_all_highest_version_gems_on_load_path
- $" << File.join(Gem::ConfigMap[:libdir], "ruby",
+ $" << File.join(Gem::ConfigMap[:libdir], Gem::ConfigMap[:ruby_install_name],
Gem::ConfigMap[:ruby_version], "rubygems.rb")
rescue Exception => e
puts "Error loading gem paths on load path in gem_prelude"
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macruby-changes/attachments/20090306/648489f8/attachment.html>
More information about the macruby-changes
mailing list