[Rubygems-developers] check gem version before gem installation? (or: how to add rubygem version dependencies now that there is no 'rubygems' gem?)

Nate Murray nate at natemurray.com
Thu Sep 18 14:02:54 EDT 2008

Hey all,
I've just created a new gem. I'm using hoe 1.7.0 and it uses the
rubygems method "add_development_dependency" which was added approx
rubygems 1.2.0.

In order for my gem to install correctly it needs to run a rake task
to finish installation. If one installs the gem with rubygems version
< 1.2.0. Then 1) the gem will "install" (place files in the gems home)
but 2) the rake task fails because it cannot find the method
"add_development_dependency" and installation does not complete.

As I understand it, I cannot just add a requirement of rubygems >=
1.2.0 because there is no longer a rubygem gem. (is this accurate?)

I have the following method which will check the rubygems version:

def check_rubygems_version
  min_version = '1.2.0'
  local_version = %x[gem --version].chomp

  unless local_version >= min_version
    puts "You need to update the RubyGems utility to #{min_version}
using the following"
    puts ""
    puts " sudo gem update --system"

My problem is this: how do I get this method to run *before*
installation. For instance, when someone does "gem install natesgem"
how do I have this method run and say "You need to update RubyGems
..." etc. ?

The gem requirements dont seem to take a lambda, as far as I can tell.
The gem specification manual comes up short as well. Any thoughts?


More information about the Rubygems-developers mailing list