The BootLoader class has a clean design for defining the initialization sequence, it just took me a while to get that 'ahhh' moment. Probably because I'm a moron.
In bootloader.rb, there are several sub-classes of Merb::BootLoader defined. As each subclass is instantiated, they are pushed into an array of subclasses via the inherited method on the Merb::BootLoader class. When the run method in Merb::BootLoader is called the subclass array is processed and the run method of each subclass is called. Very nice setup.
So, here's a list of the classes in the order they will be processed. The names should be decriptive enough to give you an idea of their functionality:
- Merb::BootLoader::Logger
- Merb::BootLoader::DropPidFile
- Merb::BootLoader::BuildFramework
- Merb::BootLoader::Dependencies
- Merb::BootLoader::BeforeAppRuns
- Merb::BootLoader::LoadClasses
- Merb::BootLoader::Templates
- Merb::BootLoader::MimeTypes
- Merb::BootLoader::AfterAppLoads
- Merb::BootLoader::MixinSessionController
- Merb::BootLoader::ChooseAdapter
- Merb::BootLoader::RackUpApplication
- Merb::BootLoader::ReloadClasses
- Merb::BootLoader::ReloadTemplates
The Merb::BootLoader::Dependencies class does a few actions that can't be inferred from the name. The run method on this class calls the following (in this order):
- load_initfile
- load_env_config
- enable_json_gem
- load_dependencies
- update_logger
Merb::BootLoader.before_app_loads do
#Stuff you want to do before your application loads
end
Merb::BootLoader.after_app_loads do
#Stuff you want to do after you application loads
end
What was confusing me was the reference to app. It seems clear now, but I was thinking this included everything: the Merb framework classes and the application classes (models, controllers, etc...) you write. This actually refers to your application code. Do stuff before Merb loads your code or do it after.
The before_app callbacks are processed in the run method of Merb::BootLoader::BeforeAppRuns. As you can see from above, this is before the Merb::BootLoader::LoadClasses. This is the class that processes everything in the load paths for your application. The Merb::BootLoader::AfterAppLoads processes the after_load callbacks.
My initializers post has been updated to reflect this new information.
I hope someone will find this useful.
back to Merb index

0 comments:
Post a Comment