Rails: How to force plugins loading in 2.0 0

Posted by luca
on Monday, October 08

Sometimes a Rails plugin can be dependant from another one. Since plugins are loaded in alphabetic order, probably you need to load the third part plugin first.

The release 1.2.4 2.0PR introduces breaking changes for this mechanism.

I'm developing a plugin called ClickToGlobalize, that's dependant on Globalize, here the code for plugin initialization:

# Force Globalize loading.
if Rails::VERSION::STRING.match /^1\.2+/
  load_plugin(File.join(RAILS_ROOT, 'vendor', 'plugins', 'globalize'))
else
  Rails::Initializer.run { |config| config.plugins = [ :globalize ] }
end

require 'click_to_globalize'

Explanation

Use the old mechanism if the current release is minor than the last release with it (1.2.3 1.2.4), else use the Rails::Initializer class.

This code also works if you use the Rails edge into app/vendor/rails.

UPDATE: Ooops, wrong version reporting, the breaking changes are in 2.0PR. The release 1.2.4 still uses #load_plugin.

Comments

Leave a response

Comment