[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: PATCH for gem2deb: gem2tgz will pick the newest gemfile instead of the first one



On Mon, Feb 27, 2012 at 05:18:34PM +0100, Matijs van Zuijlen wrote:

> I would definitely check the actual version of the gem rather than
> the mtime. There are all kinds of reasons an earlier version might
> have a later mtime accidentally.

Thanks for your feedback. Here is thus a second attempt, with the use of
Gem::Version.

I thought about writing a test for that, but this part is used
only when a gem is fetched. If we don't want to assume that we have a
network connection during the tests, I imagine that we need to create a
local gem repository, with two versions of the same simple gem, and
fetch from there.

Cédric
From c350c16494988b0bf9d42cca84ac580ff6a79d46 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?C=C3=A9dric=20Boutillier?= <cedric.boutillier@gmail.com>
Date: Mon, 27 Feb 2012 15:36:43 +0100
Subject: [PATCH] choose most recent version of the gem file instead of the
 first one

---
 bin/gem2tgz |   10 +++++++++-
 1 files changed, 9 insertions(+), 1 deletions(-)

diff --git a/bin/gem2tgz b/bin/gem2tgz
index b28d57d..2b1aeea 100755
--- a/bin/gem2tgz
+++ b/bin/gem2tgz
@@ -18,6 +18,8 @@
 require 'gem2deb'
 require 'gem2deb/gem2tgz'
 require 'optparse'
+require 'rubygems'
+
 
 optparse = OptionParser.new do |opts|
   opts.on('-h', '--help', 'show help') do
@@ -42,7 +44,13 @@ gemfile = ARGV[0]
 if not File::exists?(gemfile) and gemfile !~ /.gem$/
   puts "#{gemfile} doesn't seem to exist. Let's try to download it with 'gem fetch #{ARGV[0]}'"
   run("gem fetch #{gemfile}")
-  gemfile = Dir::glob("#{gemfile}-*.gem")[0]
+  # list all the versions present in the current directory
+  versions = Dir::glob("#{gemfile}-*.gem").map do |a|
+    Gem::Version.new(a.sub(/#{gemfile}-(.+)\.gem/, '\1'))
+  end
+  # and pick the most recent one
+  last_version = versions.max
+  gemfile = "#{gemfile}-#{last_version}.gem"
 end
 
 Gem2Deb::Gem2Tgz.convert!(gemfile, ARGV[1] || nil)
-- 
1.7.9.1

Attachment: signature.asc
Description: Digital signature


Reply to: