diff options
Diffstat (limited to 'lib/rubygems/specification.rb')
-rw-r--r-- | lib/rubygems/specification.rb | 32 |
1 files changed, 18 insertions, 14 deletions
diff --git a/lib/rubygems/specification.rb b/lib/rubygems/specification.rb index d59f57c49f..4e1a3a3801 100644 --- a/lib/rubygems/specification.rb +++ b/lib/rubygems/specification.rb @@ -182,6 +182,7 @@ class Gem::Specification < Gem::BasicSpecification @@default_value[k].nil? end + @@stubs = nil @@stubs_by_name = {} # Sentinel object to represent "not found" stubs @@ -800,10 +801,8 @@ class Gem::Specification < Gem::BasicSpecification def self.stubs @@stubs ||= begin pattern = "*.gemspec" - stubs = installed_stubs(dirs, pattern) + default_stubs(pattern) - stubs = stubs.uniq {|stub| stub.full_name } + stubs = stubs_for_pattern(pattern, false) - _resort!(stubs) @@stubs_by_name = stubs.select {|s| Gem::Platform.match_spec? s }.group_by(&:name) stubs end @@ -820,26 +819,31 @@ class Gem::Specification < Gem::BasicSpecification end end - EMPTY = [].freeze # :nodoc: - ## # Returns a Gem::StubSpecification for installed gem named +name+ # only returns stubs that match Gem.platforms def self.stubs_for(name) - if @@stubs_by_name[name] - @@stubs_by_name[name] + if @@stubs + @@stubs_by_name[name] || [] else - pattern = "#{name}-*.gemspec" - stubs = installed_stubs(dirs, pattern).select {|s| Gem::Platform.match_spec? s } + default_stubs(pattern) - stubs = stubs.uniq {|stub| stub.full_name }.group_by(&:name) - stubs.each_value {|v| _resort!(v) } - - @@stubs_by_name.merge! stubs - @@stubs_by_name[name] ||= EMPTY + @@stubs_by_name[name] ||= stubs_for_pattern("#{name}-*.gemspec") end end + ## + # Finds stub specifications matching a pattern from the standard locations, + # optionally filtering out specs not matching the current platform + # + def self.stubs_for_pattern(pattern, match_platform = true) # :nodoc: + installed_stubs = installed_stubs(Gem::Specification.dirs, pattern) + installed_stubs.select! {|s| Gem::Platform.match_spec? s } if match_platform + stubs = installed_stubs + default_stubs(pattern) + stubs = stubs.uniq {|stub| stub.full_name } + _resort!(stubs) + stubs + end + def self._resort!(specs) # :nodoc: specs.sort! do |a, b| names = a.name <=> b.name |