Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Added time sort option for list command #617

Open
wants to merge 3 commits into from

2 participants

@zachrab

@drbrain made the changes let me know if it's acceptable. Also the tests don't run correctly using 'rake'.

lib/rubygems/name_tuple.rb
@@ -6,9 +6,10 @@
require 'rubygems/platform'
class Gem::NameTuple
- def initialize(name, version, platform="ruby")
+ def initialize(name, version, date, platform="ruby")
@drbrain Owner
drbrain added a note

Adding date to NameTuple won't work as the NameTuple is only supposed to have enough information to construct the name of a gem. (See further comments)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
lib/rubygems/commands/query_command.rb
@@ -162,11 +162,14 @@ def output_query_results(spec_tuples)
spec_tuples.each do |spec_tuple, source|
versions[spec_tuple.name] << [spec_tuple, source]
end
-
- versions = versions.sort_by do |(n,_),_|
- n.downcase
+ versions = versions.sort_by do |(n,_), tuples|
+ if options[:time]
+ tuples.first.first.date
@drbrain Owner
drbrain added a note

At this point you don't (yet) have the gem specification which holds the date. You will need to fetch it, see: https://github.com/rubygems/rubygems/blob/e07d5febb5d5b75be67fb861d9bae709d5a944c8/lib/rubygems/commands/query_command.rb#L214

You should also sort by date then name:

[tuples.first.first.date, n.downcase]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
lib/rubygems/commands/query_command.rb
((13 lines not shown))
end
-
+
@drbrain Owner
drbrain added a note

Please remove trailing whitespace

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@drbrain
Owner

Moving this to the 2.3 milestone.

@chriseckhardt chriseckhardt referenced this pull request from a commit in chriseckhardt/rubygems
@melissavoegeli melissavoegeli Issue #617 Ruby Dependency on rubygem show page c9ef5cb
@chriseckhardt chriseckhardt referenced this pull request from a commit in chriseckhardt/rubygems
@melissavoegeli melissavoegeli Issue #617 word unit tests differently 7ddfc4c
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Aug 7, 2013
  1. @zachrab
Commits on Aug 11, 2013
  1. @zachrab

    Refactored list time sort

    zachrab authored
  2. @zachrab

    Removed whitespace

    zachrab authored
This page is out of date. Refresh to see the latest.
View
4 lib/rubygems/commands/list_command.rb
@@ -9,6 +9,10 @@ class Gem::Commands::ListCommand < Gem::Commands::QueryCommand
def initialize
super 'list', 'Display gems whose name starts with STRING'
+
+ add_option('-t', '--time', 'Sort gem(s) according to latest version release') do |value, options|
+ options[:time] = value
+ end
remove_option('--name-matches')
end
View
16 lib/rubygems/commands/query_command.rb
@@ -162,9 +162,12 @@ def output_query_results(spec_tuples)
spec_tuples.each do |spec_tuple, source|
versions[spec_tuple.name] << [spec_tuple, source]
end
-
- versions = versions.sort_by do |(n,_),_|
- n.downcase
+ versions = versions.sort_by do |(n,_), tuples|
+ if options[:time]
+ [tuples.first[1].date, n.downcase]
+ else
+ n.downcase
+ end
end
output_versions output, versions
@@ -210,6 +213,7 @@ def entry_details entry, detail_tuple, specs, platforms
spec_authors entry, spec
spec_homepage entry, spec
spec_license entry, spec
+ spec_date entry, spec
spec_loaded_from entry, spec, specs
spec_summary entry, spec
end
@@ -261,6 +265,12 @@ def spec_homepage entry, spec
entry << "\n" << format_text("Homepage: #{spec.homepage}", 68, 4)
end
+
+ def spec_date entry, spec
+ return if spec.date.nil?
+
+ entry << "\n" << format_text("Date: #{spec.date.strftime('%b %d, %Y')}", 68, 4)
+ end
def spec_license entry, spec
return if spec.license.nil? or spec.license.empty?
Something went wrong with that request. Please try again.