# Plugin Loading Changes

**URL:** <https://www.ruby-forum.com/t/plugin-loading-changes/49703>\
**Category:** Rails\
**Created:** [December 7, 2005, 9:37pm UTC](https://www.ruby-forum.com/t/plugin-loading-changes/49703 "2005-12-07T21:37:00Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![jeremyevans0](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/f04885/32.png) [@jeremyevans0](https://www.ruby-forum.com/u/jeremyevans0)\
**Post date:** [December 7, 2005, 9:37pm UTC](https://www.ruby-forum.com/t/plugin-loading-changes/49703/1 "2005-12-07T21:37:00Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![jeremyevans0](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/f04885/32.png) [@jeremyevans0](https://www.ruby-forum.com/u/jeremyevans0)\
**Post date:** [December 7, 2005, 10:01pm UTC](https://www.ruby-forum.com/t/plugin-loading-changes/49703/2 "2005-12-07T22:01:36Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![jeremyevans0](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/f04885/32.png) [@jeremyevans0](https://www.ruby-forum.com/u/jeremyevans0)\
**Post date:** [December 7, 2005, 10:13pm UTC](https://www.ruby-forum.com/t/plugin-loading-changes/49703/3 "2005-12-07T22:13:54Z")

</div>

On 12/7/05, Jeremy K. [removed\_email\_address@domain.invalid](mailto: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’

---

<div class="post-metadata">

**Author:** ![jeremyevans0](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/f04885/32.png) [@jeremyevans0](https://www.ruby-forum.com/u/jeremyevans0)\
**Post date:** [December 16, 2005, 4:03pm UTC](https://www.ruby-forum.com/t/plugin-loading-changes/49703/4 "2005-12-16T16:03:00Z")

</div>

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/2723)  
[http://dev.rubyonrails.org/ticket/2757](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
