Plugems Dependency Loading: Part 2 - Bundling a plugin as a Gem and getting it all to work
Plugins live in the project root, so Rails need only loop through the plugins, unshift them onto the load path, and require their init files. In a plugem environment, it's a little more complicated (to implement, not to use.)
Each of our applications has a manifest file. This is simply a YAML file that has some basic metadata about the appication (name, version, etc.) as well as a list of all of that application's plugem dependencies. This manifest file has two applications:
- Our rake tasks use it to generate a gemspec file for application gemification
- The bootstrapper uses it as a list of dependent plugems to load
Without getting into the weeds, this is accomplished in the following way:
- A bootstrap set of tasks is loaded right after the environment is booted.
- The bootstrap monkeypatches the Rails initializer, alias-chaining our plugem-loading code to plugin load.
- Upon startup, the plugem bootstrap code will loop through the dependencies and load and initialize them all. This is all mostly handled via require_gem, as our gemspec generator automatically registers the equivalent 'init.rb' type initialization via gem autorequire.
Next time: We put views, rake tasks, and layouts in these things too!