Looking for some good ideas for this...
I have a desktop app that uses a plugin system to organise various file
converters. You can see the code here:
Plugins are defined by subclassing Plugin, which calls an inherited hook to
add them to the plugin registry, and the top level app calls
Plugin.load_all, which basically does a glob of all files under plugins/
and calls `require #{file}` on each in turn.
I'm now trying to use some of the individual plugins as a library in
another app, and I ran into the annoying issue that the plugin code
subclasses Plugin, it wants plugin.rb to be required first. This is clearly
an issue with my code, since I have been relying on the plugins only loaded
via Plugin.load_all, and I should technically add require_relative
"../plugin" to each of them. However this made me realise that the whole
thing feels like a bit of a code smell, since other than that subclass hook
the plugins themselves are independent of the base class and should be
usable in isolation.
Is there a nicer way to accomplish both goals:
1. The main app should autodiscover and load everything in the plugins/
directory, and have the relevant classes register themselves
2. I should be able to just say `require pangrid/plugin/foo` to use one
plugin by itself without going through the plugin system
martin