开发者

Rails engines depending application code?

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 sh开发者_JAVA技巧ould this be considered an abuse of the plugin/engine system? Or is this one potential useful application of Rails engines?

Brendon.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜