method
output_query_results

v1_9_3_392 -
Show latest stable
-
0 notes -
Class: QueryCommand
- 1_8_6_287
- 1_8_7_72
- 1_8_7_330
- 1_9_1_378
- 1_9_2_180
- 1_9_3_125 (0)
- 1_9_3_392 (0)
- 2_1_10 (0)
- 2_2_9 (0)
- 2_4_6 (0)
- 2_5_5 (0)
- 2_6_3 (0)
- What's this?
output_query_results(spec_tuples)
private
Hide source
# File lib/rubygems/commands/query_command.rb, line 134 def output_query_results(spec_tuples) output = [] versions = Hash.new { |h,name| h[name] = [] } spec_tuples.each do |spec_tuple, source_uri| versions[spec_tuple.first] << [spec_tuple, source_uri] end versions = versions.sort_by do |(name,_),_| name.downcase end versions.each do |gem_name, matching_tuples| matching_tuples = matching_tuples.sort_by do |(_, version,_),_| version end.reverse platforms = Hash.new { |h,version| h[version] = [] } matching_tuples.map do |(_, version, platform,_),_| platforms[version] << platform if platform end seen = {} matching_tuples.delete_if do |(_, version,_),_| if seen[version] then true else seen[version] = true false end end entry = gem_name.dup if options[:versions] then list = if platforms.empty? or options[:details] then matching_tuples.map { |(_, version,_),_| 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 spec = if detail_tuple.first.length == 4 then detail_tuple.first.last else uri = URI.parse detail_tuple.last Gem::SpecFetcher.fetcher.fetch_spec detail_tuple.first, uri end entry << "\n" non_ruby = platforms.any? do |_, pls| pls.any? { |pl| pl != Gem::Platform::RUBY } end if non_ruby then 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 authors = "Author#{spec.authors.length > 1 ? 's' : ''}: " authors << spec.authors.join(', ') entry << format_text(authors, 68, 4) 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 if spec.homepage and not spec.homepage.empty? then entry << "\n" << format_text("Homepage: #{spec.homepage}", 68, 4) end 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 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 |(_,version,_,s),| loaded_from = File.dirname File.dirname(s.loaded_from) entry << "\n" << " #{label} (#{version}): #{loaded_from}" label = ' ' * label.length end end end entry << "\n\n" << format_text(spec.summary, 68, 4) end output << entry end say output.join(options[:details] ? "\n\n" : "\n") end