[Rubygems-developers] Thoughts on handling bin and man files

Jim Weirich jim at weirichhouse.org
Sat Mar 20 09:46:38 EST 2004


Richard Kilmer wrote:

> if you run the 'rake' script it would normally have:
> 
>   require 'rake'
> 
> at the top of the script...this is bad...because if you just run this 
> script the gem for rake has not been loaded.
> 
> if this changes to...
> 
>   require 'rubygems'
>   require_gem 'rake'
> 
> ...then this executable script is dependent on RubyGems, which limits 
> its usability outside of RubyGems (as a .tar.gz).
> 
> now, what if the installed 'rake' executable was generated by our gem 
> installer that would have:
> 
>   require 'rubygems'
>   require_gem 'rake', "= 0.3.0" #=> or whatever version of the gem this 
> was generated for.
>   load 'bin/rake'  #=> or whatever the binary that this is referring to is.
> 
> then we would effectively be 'wrapping' the 'rake' executable script.  
> Also, we could generate at .cmd on Win32 instead of a chmod +x script 
> file.  As well, its easier to identify these for removal upon gem 
> uninstall.

The idea appeals to me on several levels.  As you point out, it 
addresses the "where do we put applications" issue.  But it also hints 
at a way to address the "is this library a gem or not" issue.

Consider the following.  I'm writing an app that uses lafcadio (for 
instance).  Which of the following should I use:

    require 'lafcadio'      or       require_gem 'lafcadio'

It depends upon how lafcadio was installed!  If it was a gem or not. 
Perhaps applications should be written like this..

In app-nongem we write ...
    require 'lafcadio'

and in app-gem we write ..

    require 'rubygems'
    require_gem 'lafcadio', '>= 0.3.0'
    require_gem 'some_other_lib', '=1.0.0'

    load 'bin/app-non-gem'

The app-nongem doesn't worry about gems and can be installed directly in 
a non-gem environment (which I believe will become increasingly rare). 
The app-gem script can be installed if there are gems we need to 
resolve.  This isolates the part of the code that worries about version 
into a single module (probably a good thing).

BTW, currently rake does this to handle gem vs non-gem installations ...

   begin
     require 'rake'
   rescue LoadError
     require 'rubygems'
     require_gem 'rake'
   end
   RakeApp.new.run

That's the entire script for rake.  Everything is in the library.

-- 
-- Jim Weirich    jim at weirichhouse.org     http://onestepback.org
-----------------------------------------------------------------
"Beware of bugs in the above code; I have only proved it correct,
not tried it." -- Donald Knuth (in a memo to Peter van Emde Boas)



More information about the Rubygems-developers mailing list