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

Re: Bug#293055: Progress with rails?



On Sat, Feb 12, 2005 at 06:44:45AM +0100, Adeodato Simó wrote:
> * Marcelo E. Magallon [Mon, 07 Feb 2005 18:23:08 -0600]:
> >  That's what I meant by 'not source level compatible'.  Yes, I know
> >  about this:
> >
> >  begin
> >     require 'foo'
> >  rescue LoadError
> >     require 'rubygems'
> >     require_gem 'bar', '>= 1'
> >  end
> 
>   Uhm, is 'require_gem' still the most common method? I mean, I had the
>   (perhaps wrong) impression that with the 'require hack' in RubyGems 0.8
>   people would just write:
> 
>     require 'rubygems'
>     require 'somegem'
> 
>   (Yes, that does not provide a mean to impose a version constraint.)

Yes that's right, quoting from the RubyGems 0.8.4 source:
---
  # We replace Ruby's require with our own, which is capable of loading gems on demand.
  #
  # When you call <tt>require 'x'</tt>, this is what happens:
  # * If the file can be loaded from the existing Ruby loadpath, it is.
  # * Otherwise, installed gems are searched for a file that matches. If it's found in gem
  #   'y', that gem is activated (added to the loadpath).
  #
  # The normal <tt>require</tt> functionality of returning false if that file has already been
  # loaded is preserved.
---

The require override first does a linear search through all Gems and
then it falls back to the normal require.
IMO a hack which results in a nice layer, but this still doesn't solve
the source incompatibility problem because some systems might not have
RubyGems installed and can still work since the library is provided via
Debian or RPA or site local install.

A solution could be to let the "Ruby super package" (whatever it is
going to be called) install a rubygems.rb that does nothing but give
warnings until someone installs the real Rubygems package which diverts
it. 

---
# rubygems.rb - dummy lib

warn "Rubygems required but not installed, falling back to local installed libs."

module Kernel

  def require_gem(path)
    warn "require_gem should not be used when RubyGems are not installed, "
         "falling back to local installed libs."
    require(path)
  end

end
---

It would bring source compatibility for Debian for both gem and not
non-gem applications/libraries.  However, this too, is a hack and I am
not sure what will happen if someone installs RubyGems from
source/natively.

> > Even if this code is very Ruby-like, _it_ _is_ _not_ what the
> >  (rubygems) documentation says you should do.
> 
>   Does the rubygems docs advise to use 'require_gem' in all cases?

Hmm, the user quide still does so. Maybe this is because require_gem can
do something extra, namely one can add a version requirement:

  require_gem "gem_name", [version_requirement]

Greetings,

Paul

-- 
Student @ Eindhoven                         | email: paulvt@debian.org
University of Technology, The Netherlands   | JID: paul@luon.net
>>> Using the Power of Debian GNU/Linux <<< | GnuPG key ID: 0x50064181



Reply to: