diff options
author | drbrain <drbrain@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2013-07-22 22:46:50 +0000 |
---|---|---|
committer | drbrain <drbrain@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2013-07-22 22:46:50 +0000 |
commit | 4c2304f0004e9f1784540f3d36976aad9eab1f68 (patch) | |
tree | fe5d7f52b7e01644d0a57316aab03299ed0ee5c8 /lib/rubygems.rb | |
parent | 66cc0fa4abde68ae360ba2d2cdf4e44bc833e33a (diff) | |
download | ruby-4c2304f0004e9f1784540f3d36976aad9eab1f68.tar.gz |
* lib/rubygems: Import RubyGems from master as of commit b165260
* test/rubygems: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@42124 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib/rubygems.rb')
-rw-r--r-- | lib/rubygems.rb | 54 |
1 files changed, 45 insertions, 9 deletions
diff --git a/lib/rubygems.rb b/lib/rubygems.rb index 4cc2e6ea50..0c9dc759b4 100644 --- a/lib/rubygems.rb +++ b/lib/rubygems.rb @@ -446,16 +446,12 @@ module Gem # $LOAD_PATH for files as well as gems. # # Note that find_files will return all files even if they are from different - # versions of the same gem. + # versions of the same gem. See also find_latest_files def self.find_files(glob, check_load_path=true) files = [] - if check_load_path - files = $LOAD_PATH.map { |load_path| - Dir["#{File.expand_path glob, load_path}#{Gem.suffix_pattern}"] - }.flatten.select { |file| File.file? file.untaint } - end + files = find_files_from_load_path glob if check_load_path files.concat Gem::Specification.map { |spec| spec.matches_for_glob("#{glob}#{Gem.suffix_pattern}") @@ -468,6 +464,40 @@ module Gem return files end + def self.find_files_from_load_path glob # :nodoc: + $LOAD_PATH.map { |load_path| + Dir["#{File.expand_path glob, load_path}#{Gem.suffix_pattern}"] + }.flatten.select { |file| File.file? file.untaint } + end + + ## + # Returns a list of paths matching +glob+ from the latest gems that can be + # used by a gem to pick up features from other gems. For example: + # + # Gem.find_latest_files('rdoc/discover').each do |path| load path end + # + # if +check_load_path+ is true (the default), then find_latest_files also + # searches $LOAD_PATH for files as well as gems. + # + # Unlike find_files, find_latest_files will return only files from the + # latest version of a gem. + + def self.find_latest_files(glob, check_load_path=true) + files = [] + + files = find_files_from_load_path glob if check_load_path + + files.concat Gem::Specification.latest_specs(true).map { |spec| + spec.matches_for_glob("#{glob}#{Gem.suffix_pattern}") + }.flatten + + # $LOAD_PATH might contain duplicate entries or reference + # the spec dirs directly, so we prune. + files.uniq! if check_load_path + + return files + end + ## # Finds the user's home directory. #-- @@ -947,7 +977,7 @@ module Gem ## # Load +plugins+ as Ruby files - def self.load_plugin_files(plugins) + def self.load_plugin_files plugins # :nodoc: plugins.each do |plugin| # Skip older versions of the GemCutter plugin: Its commands are in @@ -965,10 +995,16 @@ module Gem end ## - # Find all 'rubygems_plugin' files in installed gems and load them + # Find the 'rubygems_plugin' files in the latest installed gems and load + # them def self.load_plugins - load_plugin_files find_files('rubygems_plugin', false) + # Remove this env var by at least 3.0 + if ENV['RUBYGEMS_LOAD_ALL_PLUGINS'] + load_plugin_files find_files('rubygems_plugin', false) + else + load_plugin_files find_latest_files('rubygems_plugin', false) + end end ## |