Re: plugin dependencies

Aaron Pfeifer
Wed, 19 Sep 2007 14:38:54 -0000

I thought I''d offer my 2 cents on the subject.  plugin_dependencies
has evolved since that article was written.  I never use
require_plugin anymore and instead rely on simply calling require,
which allows the dependency to be loaded either as a plugin or as a
gem.  As is, my plugin development practices allow me to release
plugins as both a Rails plugin and a Ruby gem.

Say we have 2 plugins, encrypted_strings and encrypted_attributes
(which depends on encrypted_strings).  In this case, we do the
following:

encrypted_attributes/init.rb:
require ''encrypted_attributes''

encrypted_attributes/lib/encrypted_attributes.rb:
require ''encrypted_strings''
...do stuff...

With plugin_dependencies loaded, this will look for encrypted_strings
as either a vendor/plugin within the application or as a gem.  This
lets me be flexible in case I want the same plugin/gem/whatever used
across multiple applications in a single environment.  The basic idea
is that we''re not specifically tying a library as a plugin using
require_plugin, but instead treating it the same as you do with Rails
either being loaded locally in vendor/ or as a gem.

With regard to partial loading, both myself and James Adam use the
following technique:

Rails::Initializer.run do |config|
  config.plugins = %w(
    plugins_plus
    something_else
    *
   )
end

This is currently available as a plugin (partial_plugin_list).  Not
sure if it''s the best syntax, but it''s there if you need it.

I really do think that dependencies between plugins/gems are
important.  If you browse through all of the PluginAWeek plugins,
you''ll notice several dependencies (has_emails depending on
validates_as_email_address, user_authentication depending on
encrypted_attributes).  In some cases, the dependent library *must* be
loaded before continuing and in other cases it doesn''t.  However, my
whole argument behind adding "require" for each dependency has been
that this information belongs in the plugin and not in a
configuration.  This way, I don''t have to duplicate that configuration
in every application I use those plugins.

Hope this helps :)