Forum: Ruby on Rails Plugin Loading Changes

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
jeremyevans0 (Guest)
on 2005-12-07 22:37
(Received via mailing list)
Currently plugins load as follows (psuedocode):

for each plugin directory:
  add plugin directory/lib to $LOAD_PATH (if it exists)
  execute plugin directory/init.rb

I think it would be better to change this to:

for each plugin directory:
  add plugin directory/lib to $:
for each plugin directory:
  execute plugin directory/init.rb

The reason for this is that I have a general plugin that does a lot of
stuff, and a specific one that extends part of it for a specific site
(so the specific plugin depends on the general one).  I'd like to be
able to do:

# in specific_plugin/init.rb
require 'general_plugin'
require 'specific_plugin'

However, this fails if specific plugin is loaded before general plugin
(and you can't choose the order).  You can fix it by doing:

# in specific_plugin/init.rb
$:.push(File.join(RAILS_ROOT, 'vendor', 'plugins', 'general_plugin',
'lib'))
require 'general_plugin'
require 'specific_plugin'

Obviously, I'd just like to eliminate that additional line.  After
poking around in the source, I tried this:

# in specific_plugin/init.rb
load_plugin 'general_plugin'
require 'specific_plugin'

But that doesn't work, probably because it doesn't have the full path.
 This is probably the best I can do at this point:

# in specific_plugin/init.rb
load_plugin File.join(RAILS_ROOT, 'vendor', 'plugins', 'general_plugin')
require 'specific_plugin'

Any thoughts on changing plugin loading?  If other people think this
is a good idea (and the powers that be approve), it should be fairly
simple to come up with a patch.
jeremy (Guest)
on 2005-12-07 23:01
(Received via mailing list)
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On Dec 7, 2005, at 12:33 PM, Jeremy E. wrote:
> for each plugin directory:
>   execute plugin directory/init.rb

Lib dirs are added before any inits are called in 1.1.
Could you try on svn trunk?

jeremy
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.2 (Darwin)

iD8DBQFDl0ypAQHALep9HFYRAhN6AKDGINIpLmkP7ZcrFz15mUo6JRn/KACcDZBl
MWcx0s8yvnvSi1mBN5um8t8=
=+AH6
-----END PGP SIGNATURE-----
jeremyevans0 (Guest)
on 2005-12-07 23:13
(Received via mailing list)
On 12/7/05, Jeremy K. <removed_email_address@domain.invalid> wrote:
> Lib dirs are added before any inits are called in 1.1.
> Could you try on svn trunk?

I did rake freeze_edge and tried:

# in specific_plugin/init.rb
require 'general_plugin'
require 'specific_plugin'

and this:

# in specific_plugin/init.rb
load_plugin 'general_plugin'
require 'specific_plugin'

Both of which failed. I checked the load path and not all plugin lib
directories are in it when it loads specific_plugin/init.rb.

This still worked:

# in specific_plugin/init.rb
load_plugin File.join(RAILS_ROOT, 'vendor', 'plugins', 'general_plugin')
require 'specific_plugin'
James A. (Guest)
on 2005-12-16 17:03
(Received via mailing list)
This was a problem that we hit with engines too - essentially you
can't control the plugin load order. I think this is probably suits
the Rail's core team philosophy, which I believe to be that plugins
shouldn't depend on other plugins (correct me if this isn't accurate).

For some history:
http://dev.rubyonrails.org/ticket/2723
http://dev.rubyonrails.org/ticket/2757

... and this is exactly why there is an Engines.start command too.
With some kind of plugin dependency mechanism it would be obsolete.

- james
This topic is locked and can not be replied to.