diff options
Diffstat (limited to 'lib/rubygems/source_index.rb')
-rw-r--r-- | lib/rubygems/source_index.rb | 29 |
1 files changed, 22 insertions, 7 deletions
diff --git a/lib/rubygems/source_index.rb b/lib/rubygems/source_index.rb index 1eefd8c149..c6499ed2a8 100644 --- a/lib/rubygems/source_index.rb +++ b/lib/rubygems/source_index.rb @@ -7,7 +7,9 @@ require 'rubygems' require 'rubygems/user_interaction' require 'rubygems/specification' -require 'rubygems/spec_fetcher' +module Gem + autoload(:SpecFetcher, 'rubygems/spec_fetcher') +end ## # The SourceIndex object indexes all the gems available from a @@ -80,8 +82,14 @@ class Gem::SourceIndex def load_specification(file_name) begin - spec_code = File.read(file_name).untaint + spec_code = if RUBY_VERSION < '1.9' then + File.read file_name + else + File.read file_name, :encoding => 'UTF-8' + end.untaint + gemspec = eval spec_code, binding, file_name + if gemspec.is_a?(Gem::Specification) gemspec.loaded_from = file_name return gemspec @@ -93,7 +101,7 @@ class Gem::SourceIndex alert_warning e alert_warning spec_code rescue Exception => e - alert_warning(e.inspect.to_s + "\n" + spec_code) + alert_warning "#{e.inspect}\n#{spec_code}" alert_warning "Invalid .gemspec format in '#{file_name}'" end return nil @@ -230,7 +238,8 @@ class Gem::SourceIndex # Find a gem by an exact match on the short name. def find_name(gem_name, version_requirement = Gem::Requirement.default) - search(/^#{gem_name}$/, version_requirement) + dep = Gem::Dependency.new(/^#{gem_name}$/, version_requirement) + search dep end ## @@ -246,7 +255,13 @@ class Gem::SourceIndex version_requirement = nil only_platform = false - case gem_pattern # TODO warn after 2008/03, remove three months after + # TODO - Remove support and warning for legacy arguments after 2008/11 + unless Gem::Dependency === gem_pattern + warn "Gem::SourceIndex#search support for #{gem_pattern.class} patterns is deprecated" + warn "#{caller[0]} is outdated" + end + + case gem_pattern when Regexp then version_requirement = platform_only || Gem::Requirement.default when Gem::Dependency then @@ -270,7 +285,7 @@ class Gem::SourceIndex specs = @gems.values.select do |spec| spec.name =~ gem_pattern and - version_requirement.satisfied_by? spec.version + version_requirement.satisfied_by? spec.version end if only_platform then @@ -539,7 +554,7 @@ module Gem # objects to load properly. Cache = SourceIndex - # :starddoc: + # :startdoc: end |