diff options
Diffstat (limited to 'lib/rubygems/commands/dependency_command.rb')
-rw-r--r-- | lib/rubygems/commands/dependency_command.rb | 68 |
1 files changed, 23 insertions, 45 deletions
diff --git a/lib/rubygems/commands/dependency_command.rb b/lib/rubygems/commands/dependency_command.rb index b6840c35d4..209fdebd50 100644 --- a/lib/rubygems/commands/dependency_command.rb +++ b/lib/rubygems/commands/dependency_command.rb @@ -49,13 +49,13 @@ class Gem::Commands::DependencyCommand < Gem::Command end def execute - options[:args] << '' if options[:args].empty? - specs = {} - - source_indexes = Hash.new do |h, source_uri| - h[source_uri] = Gem::SourceIndex.new + if options[:reverse_dependencies] and remote? and not local? then + alert_error 'Only reverse dependencies for local gems are supported.' + terminate_interaction 1 end + options[:args] << '' if options[:args].empty? + pattern = if options[:args].length == 1 and options[:args].first =~ /\A\/(.*)\/(i)?\z/m then flags = $2 ? Regexp::IGNORECASE : nil @@ -64,34 +64,30 @@ class Gem::Commands::DependencyCommand < Gem::Command /\A#{Regexp.union(*options[:args])}/ end - dependency = Gem::Dependency.new pattern, options[:version] + # TODO: deprecate for real damnit + dependency = Deprecate.skip_during { + Gem::Dependency.new pattern, options[:version] + } dependency.prerelease = options[:prerelease] - if options[:reverse_dependencies] and remote? and not local? then - alert_error 'Only reverse dependencies for local gems are supported.' - terminate_interaction 1 - end + specs = [] - if local? then - Gem.source_index.search(dependency).each do |spec| - source_indexes[:local].add_spec spec - end - end + specs.concat dependency.matching_specs if local? if remote? and not options[:reverse_dependencies] then fetcher = Gem::SpecFetcher.fetcher - specs_and_sources = fetcher.find_matching(dependency, false, true, + # REFACTOR: fetcher.find_specs_matching => specs + specs_and_sources = fetcher.find_matching(dependency, + dependency.specific?, true, dependency.prerelease?) - specs_and_sources.each do |spec_tuple, source_uri| - spec = fetcher.fetch_spec spec_tuple, URI.parse(source_uri) - - source_indexes[source_uri].add_spec spec - end + specs.concat specs_and_sources.map { |spec_tuple, source_uri| + fetcher.fetch_spec spec_tuple, URI.parse(source_uri) + } end - if source_indexes.empty? then + if specs.empty? then patterns = options[:args].join ',' say "No gems found matching #{patterns} (#{options[:version]})" if Gem.configuration.verbose @@ -99,24 +95,18 @@ class Gem::Commands::DependencyCommand < Gem::Command terminate_interaction 1 end - specs = {} - - source_indexes.values.each do |source_index| - source_index.gems.each do |name, spec| - specs[spec.full_name] = [source_index, spec] - end - end + specs = specs.uniq.sort reverse = Hash.new { |h, k| h[k] = [] } if options[:reverse_dependencies] then - specs.values.each do |_, spec| + specs.each do |spec| reverse[spec.full_name] = find_reverse_dependencies spec end end if options[:pipe_format] then - specs.values.sort_by { |_, spec| spec }.each do |_, spec| + specs.each do |spec| unless spec.dependencies.empty? spec.dependencies.sort_by { |dep| dep.name }.each do |dep| say "#{dep.name} --version '#{dep.requirement}'" @@ -126,7 +116,7 @@ class Gem::Commands::DependencyCommand < Gem::Command else response = '' - specs.values.sort_by { |_, spec| spec }.each do |_, spec| + specs.each do |spec| response << print_dependencies(spec) unless reverse[spec.full_name].empty? then response << " Used by\n" @@ -158,7 +148,7 @@ class Gem::Commands::DependencyCommand < Gem::Command def find_reverse_dependencies(spec) result = [] - Gem.source_index.each do |name, sp| + Gem::Specification.each do |sp| sp.dependencies.each do |dep| dep = Gem::Dependency.new(*dep) unless Gem::Dependency === dep @@ -172,17 +162,5 @@ class Gem::Commands::DependencyCommand < Gem::Command result end - def find_gems(name, source_index) - specs = {} - - spec_list = source_index.search name, options[:version] - - spec_list.each do |spec| - specs[spec.full_name] = [source_index, spec] - end - - specs - end - end |