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!
1 comment:
About a year ago I interviewed with and was offered a position with RHG but turned it down for, what appeared to be, a more technically focused position. Yesterday I discovered your blog and have been cursing myself ever since.
"Our passion is to end the rails enterprise argument."
You guys ROCK!!
Post a Comment