views:

28

answers:

1

We have what I suspect is an unusual setup. We have a Rails app which is something we sell to customers. We also package up bundles of business features into optional addons that the clients can purchase according to their needs. We have done these as Rails plugins/engines to keep them nicely separated.

This forces the unusual requirement that all of our business plugins have a dependency on the application itself. In other words, the framework is in main Rails app folder, while the business modules are in vendor/plugins. Put another way, they're hardly plugins if they rely on a particular app folder. Or are they?

This does work, so my question is out of architectural curiosity rather than a plea for help. But should this be considered an abuse of the plugin/engine system? Or is this one potential useful application of Rails engines?

Brendon.

+1  A: 

I don't see what the issue is with a plugin having dependencies so long as these are qualified and easily understood. A Rails plugin is nothing without Rails, and often it requires a specific version.

The thing that's bad design is having a plugin which will wreck an app if it can't load properly instead of producing some kind of useful message. For instance, you might test the environment before launching in feet-first.

A very brute-force way of doing this, but at least giving feedback, might be like this in an initializer for your plug-in:

unless (defined?(MyApp))
  raise "MyAppPlugin requires MyApp to be installed"
end

You can do this more elegantly by making private gems for your app and setting the requirements more formally. The new Bundler system makes this possible.

tadman
Thanks for the reply. I think what we're doing is probably fine, just quite unusual. I'll shamelessly admit that I'm using RubyMine as an IDE and it has definitely scoped the dependencies to work in one direction only, which started to make me wonder if they were on to something. But I suppose this is the rails way. All one big soup linked together by the Rails load path in both directions.
Brendon
There's a fine line between having a tangled mess of a dependency chain and an elegant one. Most of the time the difference is in the error messages produced when things don't work out. A well designed system will give you a heads up, not just blow a stack trace. I think Passenger does a spectacular job of testing your environment before installing, plus giving you a specific path to resolution should something not work out, often a command customized for your system that you can cut and paste.
tadman