summaryrefslogtreecommitdiff
path: root/lib/rubygems/commands/query_command.rb
diff options
context:
space:
mode:
authordrbrain <drbrain@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2012-12-19 07:19:10 +0000
committerdrbrain <drbrain@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2012-12-19 07:19:10 +0000
commiteddc0685f224a6de2f5a6bdaab7f87562192ba7f (patch)
tree54f3427a70f2cc21e9dbbb6c3ad9ed500ea96865 /lib/rubygems/commands/query_command.rb
parent1b2be1f8ca5286a75d9401f96eaec89317353e3e (diff)
* lib/rubygems/commands/query_command.rb: Refactored to improve
maintainability. * test/rubygems/test_gem_commands_query_command.rb: Note default gems in gem list details. * lib/rubygems/uninstaller.rb: Detect all gems for uninstallation. This allows duplicate installs of default gems to be removed. * lib/rubygems/specification.rb: Allow use of ::each_spec. * lib/rubygems/test_case.rb: Added install_default_gems. * test/rubygems/test_gem_commands_uninstall_command.rb: Moved test down to the uninstaller tests. * test/rubygems/test_gem_uninstaller.rb: Test for uninstallation of default gems and duplicate default gems. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@38461 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib/rubygems/commands/query_command.rb')
-rw-r--r--lib/rubygems/commands/query_command.rb184
1 files changed, 109 insertions, 75 deletions
diff --git a/lib/rubygems/commands/query_command.rb b/lib/rubygems/commands/query_command.rb
index 020bc297b49..0ae7924564d 100644
--- a/lib/rubygems/commands/query_command.rb
+++ b/lib/rubygems/commands/query_command.rb
@@ -162,12 +162,18 @@ class Gem::Commands::QueryCommand < Gem::Command
n.downcase
end
+ output_versions output, versions
+
+ say output.join(options[:details] ? "\n\n" : "\n")
+ end
+
+ def output_versions output, versions
versions.each do |gem_name, matching_tuples|
matching_tuples = matching_tuples.sort_by { |n,_| n.version }.reverse
platforms = Hash.new { |h,version| h[version] = [] }
- matching_tuples.map do |n,_|
+ matching_tuples.each do |n, _|
platforms[n.version] << n.platform if n.platform
end
@@ -182,97 +188,125 @@ class Gem::Commands::QueryCommand < Gem::Command
end
end
- entry = gem_name.dup
-
- if options[:versions] then
- list = if platforms.empty? or options[:details] then
- matching_tuples.map { |n,_| n.version }.uniq
- else
- platforms.sort.reverse.map do |version, pls|
- if pls == [Gem::Platform::RUBY] then
- version
- else
- ruby = pls.delete Gem::Platform::RUBY
- platform_list = [ruby, *pls.sort].compact
- "#{version} #{platform_list.join ' '}"
- end
- end
- end.join ', '
-
- entry << " (#{list})"
- end
-
- if options[:details] then
- detail_tuple = matching_tuples.first
+ output << make_entry(matching_tuples, platforms)
+ end
+ end
- spec = detail_tuple.last
+ def entry_details entry, spec, specs, platforms
+ return unless options[:details]
- unless spec.kind_of? Gem::Specification
- spec = spec.fetch_spec detail_tuple.first
- end
+ entry << "\n"
- entry << "\n"
+ spec_platforms entry, platforms
+ spec_authors entry, spec
+ spec_homepage entry, spec
+ spec_license entry, spec
+ spec_loaded_from entry, spec, specs
+ spec_summary entry, spec
+ end
- non_ruby = platforms.any? do |_, pls|
- pls.any? { |pl| pl != Gem::Platform::RUBY }
- end
+ def entry_versions entry, name_tuples, platforms
+ return unless options[:versions]
- if non_ruby then
- if platforms.length == 1 then
- title = platforms.values.length == 1 ? 'Platform' : 'Platforms'
- entry << " #{title}: #{platforms.values.sort.join ', '}\n"
+ list =
+ if platforms.empty? or options[:details] then
+ name_tuples.map { |n| n.version }.uniq
+ else
+ platforms.sort.reverse.map do |version, pls|
+ if pls == [Gem::Platform::RUBY] then
+ version
else
- entry << " Platforms:\n"
- platforms.sort_by do |version,|
- version
- end.each do |version, pls|
- label = " #{version}: "
- data = format_text pls.sort.join(', '), 68, label.length
- data[0, label.length] = label
- entry << data << "\n"
- end
+ ruby = pls.delete Gem::Platform::RUBY
+ platform_list = [ruby, *pls.sort].compact
+ "#{version} #{platform_list.join ' '}"
end
end
+ end
- authors = "Author#{spec.authors.length > 1 ? 's' : ''}: "
- authors << spec.authors.join(', ')
- entry << format_text(authors, 68, 4)
+ entry << " (#{list.join ', '})"
+ end
- if spec.rubyforge_project and not spec.rubyforge_project.empty? then
- rubyforge = "Rubyforge: http://rubyforge.org/projects/#{spec.rubyforge_project}"
- entry << "\n" << format_text(rubyforge, 68, 4)
- end
+ def make_entry entry_tuples, platforms
+ detail_tuple = entry_tuples.first
+ name_tuple, latest_spec = detail_tuple
- if spec.homepage and not spec.homepage.empty? then
- entry << "\n" << format_text("Homepage: #{spec.homepage}", 68, 4)
- end
+ latest_spec = latest_spec.fetch_spec name_tuple unless
+ Gem::Specification === latest_spec
- if spec.license and not spec.license.empty? then
- licenses = "License#{spec.licenses.length > 1 ? 's' : ''}: "
- licenses << spec.licenses.join(', ')
- entry << "\n" << format_text(licenses, 68, 4)
- end
+ name_tuples, specs = entry_tuples.flatten.partition do |item|
+ Gem::NameTuple === item
+ end
- if spec.loaded_from then
- if matching_tuples.length == 1 then
- loaded_from = File.dirname File.dirname(spec.loaded_from)
- entry << "\n" << " Installed at: #{loaded_from}"
- else
- label = 'Installed at'
- matching_tuples.each do |n,s|
- loaded_from = File.dirname File.dirname(s.loaded_from)
- entry << "\n" << " #{label} (#{n.version}): #{loaded_from}"
- label = ' ' * label.length
- end
- end
- end
+ entry = [latest_spec.name]
+
+ entry_versions entry, name_tuples, platforms
+ entry_details entry, latest_spec, specs, platforms
+
+ entry.join
+ end
+
+ def spec_authors entry, spec
+ authors = "Author#{spec.authors.length > 1 ? 's' : ''}: "
+ authors << spec.authors.join(', ')
+ entry << format_text(authors, 68, 4)
+ end
+
+ def spec_homepage entry, spec
+ return if spec.homepage.nil? or spec.homepage.empty?
+
+ entry << "\n" << format_text("Homepage: #{spec.homepage}", 68, 4)
+ end
+
+ def spec_license entry, spec
+ return if spec.license.nil? or spec.license.empty?
- entry << "\n\n" << format_text(spec.summary, 68, 4)
+ licenses = "License#{spec.licenses.length > 1 ? 's' : ''}: "
+ licenses << spec.licenses.join(', ')
+ entry << "\n" << format_text(licenses, 68, 4)
+ end
+
+ def spec_loaded_from entry, spec, specs
+ return unless spec.loaded_from
+
+ if specs.length == 1 then
+ default = spec.default_gem? ? ' (default)' : nil
+ entry << "\n" << " Installed at#{default}: #{spec.base_dir}"
+ else
+ label = 'Installed at'
+ specs.each do |s|
+ version = s.version.to_s
+ version << ', default' if s.default_gem?
+ entry << "\n" << " #{label} (#{version}): #{s.base_dir}"
+ label = ' ' * label.length
end
- output << entry
end
+ end
- say output.join(options[:details] ? "\n\n" : "\n")
+ def spec_platforms entry, platforms
+ non_ruby = platforms.any? do |_, pls|
+ pls.any? { |pl| pl != Gem::Platform::RUBY }
+ end
+
+ return unless non_ruby
+
+ if platforms.length == 1 then
+ title = platforms.values.length == 1 ? 'Platform' : 'Platforms'
+ entry << " #{title}: #{platforms.values.sort.join ', '}\n"
+ else
+ entry << " Platforms:\n"
+ platforms.sort_by do |version,|
+ version
+ end.each do |version, pls|
+ label = " #{version}: "
+ data = format_text pls.sort.join(', '), 68, label.length
+ data[0, label.length] = label
+ entry << data << "\n"
+ end
+ end
+ end
+
+ def spec_summary entry, spec
+ entry << "\n\n" << format_text(spec.summary, 68, 4)
end
end