Plugin Loading Changes

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.

-----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-----

On 12/7/05, Jeremy K. [email protected] 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’

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